Skip to content

refactor(host): migrate BootstrapHttpClient from options to dependency injection#219

Merged
j-d-ha merged 10 commits into
mainfrom
refactor/#218-migrate-BootstrapHttpClient-from-options-to-dependency-injection
Dec 6, 2025
Merged

refactor(host): migrate BootstrapHttpClient from options to dependency injection#219
j-d-ha merged 10 commits into
mainfrom
refactor/#218-migrate-BootstrapHttpClient-from-options-to-dependency-injection

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 6, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR migrates the BootstrapHttpClient configuration from a direct property on LambdaHostOptions to a dependency injection-based approach using keyed services. This change improves testability, follows modern .NET DI patterns, and provides a more flexible way to configure the Lambda bootstrap HTTP client.

Key changes:

  • Added new extension methods AddLambdaBootstrapHttpClient() and TryAddLambdaBootstrapHttpClient() for registering custom HTTP clients via DI
  • Deprecated the LambdaHostOptions.BootstrapHttpClient property (will be removed in v2.0.0)
  • Updated LambdaBootstrapAdapter to resolve HTTP client from keyed services with fallback to the deprecated property
  • Added comprehensive unit tests for the new extension methods
  • Added Microsoft.Extensions.Http package dependency

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #218


💬 Notes for Reviewers

The deprecated BootstrapHttpClient property will continue to work until v2.0.0, ensuring backward compatibility. The keyed service registration takes precedence over the property value when both are present.

The new DI-based approach uses typeof(ILambdaBootstrapOrchestrator) as the service key to avoid conflicts with other HTTP client registrations.

j-d-ha added 10 commits December 6, 2025 08:40
- Added `Microsoft.Extensions.Http` to `AwsLambda.Host.csproj` for HTTP client support.
- Updated `Directory.Packages.props` to include `Microsoft.Extensions.Http` version 10.0.0.
…Clients

- Introduced `LambdaHttpClientServiceCollectionExtensions` for streamlined HttpClient registration.
- Added methods for registering keyed HttpClient instances or factories for `ILambdaBootstrapOrchestrator`.
…tration

- Added `TryAddLambdaBootstrapHttpClient` overloads in `LambdaHttpClientServiceCollectionExtensions`.
- Supported keyed singleton registration for `ILambdaBootstrapOrchestrator`.
- Included method to register HttpClient instances, generics, or factories.
… methods

- Removed unused `AddLambdaBootstrapHttpClient<T>()` and `TryAddLambdaBootstrapHttpClient<T>()` methods.
- Simplified `LambdaHttpClientServiceCollectionExtensions` to streamline HttpClient registration.
…aHostOptions

- Marked `BootstrapHttpClient` as obsolete with a message pointing to alternative extension methods.
- Included guidance to use `AddLambdaBootstrapHttpClient` or `TryAddLambdaBootstrapHttpClient` instead.
…thods

- Added XML documentation for `AddLambdaBootstrapHttpClient` and `TryAddLambdaBootstrapHttpClient` methods.
- Introduced new overloads for `AddLambdaBootstrapHttpClient` and `TryAddLambdaBootstrapHttpClient`.
- Supported configurations for registering HttpClient instances or factories with dependency injection.
- Improved support for mocking, testing, and user-defined HttpClient configurations.
…nExtensions

- Added comprehensive test coverage for `AddLambdaBootstrapHttpClient` methods.
- Verified exception handling for null arguments and proper service registration.
- Added tests for `TryAddLambdaBootstrapHttpClient` to ensure duplicate registrations are prevented.
- Confirmed method chaining behavior for fluent configurations.
…mbdaBootstrapAdapter

- Updated `LambdaBootstrapAdapter` to support injecting a `HttpClient` via DI for better testability.
- Deprecated direct usage of `BootstrapHttpClient` property in favor of DI-based resolution.
- Added safeguards to handle cases where the keyed service is not present, maintaining backward compatibility.
…nt property

- Clarified that keyed service registrations override the BootstrapHttpClient property.
- Included references to AddLambdaBootstrapHttpClient and TryAddLambdaBootstrapHttpClient.
…trapAdapter constructor

- Updated HttpClient parameter in `LambdaBootstrapAdapter` constructor to use a default null value.
- Improves flexibility when HttpClient is omitted or not explicitly provided.
@github-actions github-actions Bot added the type: refactor Code refactoring label Dec 6, 2025

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2025

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Dec 6, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...c/AwsLambda.Host/Runtime/LambdaBootstrapAdapter.cs 71.42% 2 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
+ Coverage   88.91%   89.01%   +0.09%     
==========================================
  Files         105      106       +1     
  Lines        2256     2275      +19     
  Branches      255      256       +1     
==========================================
+ Hits         2006     2025      +19     
  Misses        158      158              
  Partials       92       92              
Files with missing lines Coverage Δ
...ons/LambdaHttpClientServiceCollectionExtensions.cs 100.00% <100.00%> (ø)
...c/AwsLambda.Host/Core/Options/LambdaHostOptions.cs 100.00% <ø> (ø)
...c/AwsLambda.Host/Runtime/LambdaBootstrapAdapter.cs 38.09% <71.42%> (+14.56%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfa5ce3...89dc300. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j-d-ha
j-d-ha merged commit 35db78d into main Dec 6, 2025
8 checks passed
@j-d-ha
j-d-ha deleted the refactor/#218-migrate-BootstrapHttpClient-from-options-to-dependency-injection branch December 6, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(host): migrate BootstrapHttpClient from options to dependency injection

1 participant