refactor(host): migrate BootstrapHttpClient from options to dependency injection#219
Conversation
- 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.
There was a problem hiding this comment.
💡 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".
|
Codecov Report❌ Patch coverage is
@@ 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
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|

🚀 Pull Request
📋 Summary
This PR migrates the
BootstrapHttpClientconfiguration from a direct property onLambdaHostOptionsto 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:
AddLambdaBootstrapHttpClient()andTryAddLambdaBootstrapHttpClient()for registering custom HTTP clients via DILambdaHostOptions.BootstrapHttpClientproperty (will be removed in v2.0.0)LambdaBootstrapAdapterto resolve HTTP client from keyed services with fallback to the deprecated propertyMicrosoft.Extensions.Httppackage dependency✅ Checklist
🧪 Related Issues or PRs
Closes #218
💬 Notes for Reviewers
The deprecated
BootstrapHttpClientproperty 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.