feat(source-generators): support multiple MapHandler invocations with custom feature providers#214
Conversation
- Added null-checking logic to filter out null `IFeatureProvider` instances. - Simplified constructor and improved internal field initialization.
- Added null-checking logic to filter out null `IFeatureProvider` instances. - Simplified constructor and improved internal field initialization.
…p-handler' into feature/#189-support-multiple-map-handler
- Introduced `EventFeatureProviderFactory` and `ResponseFeatureProviderFactory` implementations. - Added `IEventFeatureProviderFactory` and `IResponseFeatureProviderFactory` interfaces. - Registered feature provider factories into the service collection.
- Added summary and remarks for `IResponseFeatureProviderFactory` and `IEventFeatureProviderFactory`. - Documented type parameters and return values for `Create<T>` methods.
- Updated `DefaultEventFeatureProvider` and `DefaultResponseFeatureProvider` visibility to internal. - Enhances encapsulation and restricts unnecessary exposure of types.
…om providers - Added a new `Create` method overload accepting `IEnumerable<IFeatureProvider>`. - Enables combining default and custom feature providers when creating `DefaultFeatureCollection`.
…ctory method - Updated `DefaultFeature in` `IFeatureCollectionFactory.Create` to use `.ToArray()` after concatenation. - Ensures compatibility with collections requiring fixed-size arrays from concatenation outputs.
- Added `_featureProviders` field to store custom feature providers. - Resolved `FeatureProvidersKey` from properties to populate `_featureProviders`. - Updated `DefaultLambdaHostContext` creation to pass `_featureProviders` to `Create` method.
…lectionFactory` - Deleted `IFeatureCollectionFactory.Create()` method that accepts no parameters. - Simplified `DefaultFeatureCollectionFactory` by removing unused functionality.
- Replaced internal field initialization with constructor parameter assignment. - Removed null-checking and filtering logic as it's no longer necessary. - Updated `Create` method to use the constructor-initialized `providers`.
…xtensions` - Introduced `FeatureProvidersKey` constant to store feature providers in application properties. - Added logic to resolve and assign event and response feature providers to the application. - Removed redundant `BuildInterceptor` method and associated feature provider registrations.
…ature providers - Added logic to merge existing feature providers with new ones in `application.Properties`. - Updated imports to include `System.Collections.Generic` and `System.Linq`.
…` invocations - Deleted `MultipleMethodCalls` diagnostic descriptor (`LH0001`) and its related validation logic. - Removed associated entry from `AnalyzerReleases.Unshipped.md`. - Updated `AnalyzerReleases.Shipped.md` with a comment for the released diagnostics tracking.
…rSyntaxProvider` - Removed unnecessary "Handle" argument from `HandlerInfoExtractor.Predicate` invocation.
- Added `README.md` for `AwsLambda.Host.SourceGenerators` with notes about release tracking files. - Updated `AnalyzerReleases.Shipped.md` to remove unnecessary comment.
- Introduced new `UseOpenTelemetryTracing` extension to enable tracing for Lambda events. - Added dependency on `OpenTelemetry.Instrumentation.AWSLambda` and updated service resolution logic. - Deprecated old `UseOpenTelemetryTracing` method, renamed to `UseOpenTelemetryTracing_old`.
- Refactored `MapHandlerSources.Generate` to allow multiple `MapHandler` calls with distinct signatures. - Updated template logic to iterate through multiple handler calls and generate interceptors. - Simplified `BuildHandlerParameterAssignment` by converting to an expression-bodied method. - Removed unused `MapHandlerInvocationInfo` filtering logic in `LambdaHostOutputGenerator`. - Disabled OpenTelemetry tracing generation due to incompatible mapping logic.
…neration - Added a check to skip source generation if any diagnostic has `DiagnosticSeverity.Error`. - Modified `MapHandlerSources.Generate` logic to ensure source is only generated when handlers exist.
…nse handling - Introduced `IsEventFeatureRequired` and `IsResponseFeatureRequired` flags in `MapHandlerSources`. - Updated template logic to use the new flags for determining feature provider inclusion.
…andler templates - Replaced `FeatureProvidersKey` with specific keys for event and response feature providers. - Updated template logic to add feature providers only when not already registered in properties. - Removed redundant merging logic for feature providers in the application properties.
- Removed unnecessary async lambda wrapping for `TraceAsync` method. - Updated `UseOpenTelemetryTracing` logic to improve readability and eliminate redundant code.
…ve flexibility - Added `CreateFeatureProviders` method for cleaner feature provider initialization logic. - Replaced `FeatureProvidersKey` with `EventFeatureProviderKey` and `ResponseFeatureProviderKey`. - Updated `LambdaHostContextFactory` to use arrays for feature providers instead of `IEnumerable`. - Simplified feature provider resolution using specific keys in `LambdaHostContextFactory`.
…aHostContextFactory` - Extracted repeating logic for feature provider addition into `AddIfPresent` helper method. - Removed unnecessary `#region` and `#endregion` directives for a cleaner code structure.
- Adjusted various formatting options for C#, XML, and other languages. - Enabled or refined properties like `OptimizeImports`, `Rearrange`, and wrapping behavior. - Synced cleanup profiles for improved consistency across the project.
- Deleted `LambdaOpenTelemetryAdapters` and associated extensions for unused tracing logic. - Removed related unit tests in `LambdaOpenTelemetryServiceProviderExtensionsTests`. - Streamlined `UseOpenTelemetryTracing` by simplifying middleware definition. - Eliminated outdated `UseOpenTelemetryTracing_old` with replaced new middleware strategy.
…dleware - Added comprehensive unit tests to validate `UseOpenTelemetryTracing` behavior: - Ensures `ArgumentNullException` is thrown for null invocation builder. - Verifies `InvalidOperationException` is thrown when no `TracerProvider` is registered. - Confirms proper middleware registration and builder return behavior. - Tests middleware execution flow, ensuring the next delegate is invoked correctly. - Improves test coverage for OpenTelemetry middleware in AWS Lambda scenarios.
…hots - Deleted OpenTelemetry-related unit tests in `OtelEnabledVerifyTests`. - Removed OpenTelemetry-generated snapshot files from `SourceGenerators.UnitTests`. - Updated `GeneratorTestHelpers` to remove OpenTelemetry references from metadata setup.
…ure provider handling - Replaced `BuildInterceptor` methods with refined `MapHandler aInvokerceptor0` for key consistency. - Introduced `EventFeatureProviderKey` & `ResponseFeatureProviderKey`, Execution dynamically setups feature providers into application properties. - Updated handling of application properties to prevent duplicating feature resolution or additions. - Adjusted template test logic to reflect event-response processing adjustments. `Simplify` .
- Refactored `MapHandler` to use `Request` and `Response` records for structured input-output. - Improved response with a timestamped message using `DateTime.Utcreduce verbosity`. - Removed redundant `#region` directives for cleaner code structure.
…emplate - Deleted unused `AwsLambda.Host.Core` import in `GenericHandler.scriban`. - Simplified the generated output by cleaning up unnecessary using directives.
…ency - Reordered OnShutdown interceptor generation to align with OnInit generator placement. - Improved code readability by maintaining consistent section grouping for interceptors.
…eature provider handling - Updated `Create` assertion to ensure `featureCollectionFactory` receives `IEnumerable<IFeatureProvider>`.
…se Theory and AutoNSubstituteData - Replaced Fact with Theory and AutoNSubstituteData for parameterization. - Updated Create tests to accept IEnumerable<IFeatureProvider> dependencies. - Ensured improved test coverage with consistent dependency injection handling.
…ervices count - Changed `InlineData` value from 11 to 13 in `AddLambdaHostCoreServices_RegistersExactlyNServices`. - Updated test to reflect the updated number of registered services.
…ation - Added a detailed section on `ILambdaHostContext` type-safe feature access methods. - Documented the usage of nullable, try-pattern, and required methods for event/response handling. - Included examples, method descriptions, and usage scenarios for clarity. - Enhanced readability and understanding of available middleware utilities.
- Improved documentation on `UseOpenTelemetryTracing()` middleware for Lambda invocation pipeline. - Explained dynamic event/response handling using `IEventFeature` and `IResponseFeature`. - Described interoperability with multiple handlers and various AWS Lambda event source types. - Clarified shutdown helpers' function for forcing telemetry flush during environment freeze.
- Updated documentation to detail scenarios with multiple `MapHandler` calls in the same codebase. - Added a new "Multiple MapHandler Calls" section with examples and best practices. - Explained design patterns for library-provided handlers and conditional handler registration. - Clarified runtime behavior when multiple handlers are registered, including exceptions thrown.
…lity - Removed redundant #region and #endregion directives across multiple files. - Simplified code structure to enhance maintainability and visual clarity.
|
@codex review |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #214 +/- ##
==========================================
- Coverage 90.92% 88.91% -2.02%
==========================================
Files 102 105 +3
Lines 2227 2256 +29
Branches 252 255 +3
==========================================
- Hits 2025 2006 -19
- Misses 109 158 +49
+ Partials 93 92 -1
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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".
…textFactory - Updated `AddIfPresent` method to use `List<IFeatureProvider>` instead of `ICollection<IFeatureProvider>`. - Improves clarity and ensures compatibility with existing method usage.
…ambdaHostContextFactory - Added a test to validate `Create` method retrieves features from properties. - Ensured `featureCollectionFactory` correctly receives the expected feature providers.
- Added tests for `ResponseFeatureProviderFactory` to validate the `Create` method. - Ensured it returns a `DefaultResponseFeatureProvider<T>`. - Verified it implements `IFeatureProvider`. - Added tests for `EventFeatureProviderFactory` to validate the `Create` method. - Ensured it returns a `DefaultEventFeatureProvider<T>`. - Verified it implements `IFeatureProvider`.
- Removed a repetitive section detailing middleware's seamless support for multiple event/response types. - Streamlined the documentation to improve clarity and focus on core OpenTelemetry features.
- Adjusted column alignment for better readability in type-safe feature methods table. - Ensured consistent spacing and formatting across all method descriptions.
|



🚀 Pull Request
📋 Summary
This PR implements support for multiple
MapHandlerinvocations with custom feature providers, enabling more flexible Lambda handler registration patterns. The changes include:IEventFeatureProviderFactoryandIResponseFeatureProviderFactoryinterfaces to enable custom feature provider creationMapHandler()invocations in the same applicationLambdaHostContextFactoryandDefaultFeatureCollectionFactoryto accept custom feature providers[Theory, AutoNSubstituteData]pattern for cleaner, more maintainable test code✅ Checklist
🧪 Related Issues or PRs
Closes #189
💬 Notes for Reviewers
Key architectural changes:
MapHandlertemplate now generates code that registers feature providers and handles multiple invocations correctlyAreas to focus on: