diff --git a/docs/features/open_telemetry.md b/docs/features/open_telemetry.md index f4bbad3a..f75a64d7 100644 --- a/docs/features/open_telemetry.md +++ b/docs/features/open_telemetry.md @@ -110,20 +110,21 @@ internal record Response(string Message); --- -## How It Works: Source Generation and Interceptors +## How It Works: Feature-Based Middleware -`AwsLambda.Host` relies on C# source generators to avoid runtime reflection and improve performance. The `UseOpenTelemetryTracing()` method is a key part of this system. +The `UseOpenTelemetryTracing()` method adds middleware to the Lambda invocation pipeline that automatically instruments your handlers with distributed tracing. Here's the step-by-step process: -1. The `UseOpenTelemetryTracing()` method itself is an empty placeholder. -2. At compile time, a source generator finds all calls to this method. -3. For each call it finds, it emits a C# 12 Interceptor. This interceptor replaces the empty method call with code that adds a middleware delegate to the Lambda invocation pipeline. -4. This generated middleware calls an adapter in the `AwsLambda.Host.OpenTelemetry` package, which in turn uses the official `OpenTelemetry.Instrumentation.AWSLambda` package to wrap the Lambda handler execution in a root trace span. +1. The `UseOpenTelemetryTracing()` middleware is registered in the invocation pipeline when you call the method on your Lambda application. +2. During each Lambda invocation, the middleware executes before your handler runs. +3. The middleware dynamically detects the event and response types by reading from the feature collection: + - It checks for an `IEventFeature` to get the incoming event object + - It checks for an `IResponseFeature` to get the outgoing response object +4. These event and response objects are passed to the official `OpenTelemetry.Instrumentation.AWSLambda` package, which wraps the handler execution in a root trace span. +5. The OpenTelemetry instrumentation automatically extracts trace context from supported event types (like API Gateway requests), ensuring proper distributed trace propagation across services. -This entire process happens during compilation, resulting in highly optimized code that instruments your handler without any reflection overhead at runtime. - -In contrast, the shutdown helpers (`OnShutdownFlushOpenTelemetry`, `OnShutdownFlushTracer`, and `OnShutdownFlushMeter`) are regular extension methods. They execute as-is at runtime and use the registered `TracerProvider`/`MeterProvider` instances to force-flush telemetry before Lambda freezes the environment. +The shutdown helpers (`OnShutdownFlushOpenTelemetry`, `OnShutdownFlushTracer`, and `OnShutdownFlushMeter`) are regular extension methods that execute at runtime and use the registered `TracerProvider`/`MeterProvider` instances to force-flush telemetry before Lambda freezes the environment. --- @@ -148,9 +149,13 @@ lambda.UseOpenTelemetryTracing(); // ... MapHandler, OnShutdown, etc. ... ``` -This method call acts as a compile-time trigger for a source generator. The generator intercepts the call and injects middleware into the request pipeline. This middleware is responsible for creating the root trace span for each Lambda invocation. +This method registers middleware in the invocation pipeline that wraps each handler execution in a root trace span. The middleware is responsible for: + +- Retrieving the event object from the `IEventFeature` in the feature collection (if present) +- Executing the handler and capturing the response from `IResponseFeature` (if present) +- Passing both the event and response to the underlying `OpenTelemetry.Instrumentation.AWSLambda` package -Under the covers, the source generator performs a critical task. It inspects the delegate you provided to `MapHandler` to determine the specific input and output types of your function (e.g., `APIGatewayProxyRequest`, `SQSEvent`). It then uses these types to generate a call to a generic helper method. This ensures that the underlying `OpenTelemetry.Instrumentation.AWSLambda` package receives a strongly-typed request object. By preserving the specific event type, the OpenTelemetry instrumentation can correctly extract context and attributes, such as trace parent headers from an API Gateway request, ensuring proper distributed trace propagation. +Because the middleware reads event and response types dynamically from the feature collection, it works seamlessly with any Lambda event source type. The OpenTelemetry instrumentation can correctly extract context and attributes from strongly-typed event objects (such as trace parent headers from an API Gateway request), ensuring proper distributed trace propagation across your services. ### Gracefully Shutdown & Cleaning Up diff --git a/docs/guides/handler-registration.md b/docs/guides/handler-registration.md index 1fe15230..0c8241ad 100644 --- a/docs/guides/handler-registration.md +++ b/docs/guides/handler-registration.md @@ -33,10 +33,55 @@ interface IGreetingService } ``` -- Register middleware (via `lambda.Use(...)`) before calling `MapHandler`; the handler is always the last piece of the pipeline. -- Only one handler can be mapped. If you call `MapHandler` twice, the generator emits error `LH0001` so you catch the issue before publishing. +- While you can have multiple `MapHandler` calls in your code, only one can be registered at runtime (see [Multiple MapHandler Calls](#multiple-maphandler-calls) below). - The generated handler feeds into the normal invocation builder, so all middleware, features, and diagnostics apply equally to handlers created via `Handle` or `MapHandler`. +## Multiple MapHandler Calls + +You can have multiple `MapHandler` calls in your code, but **only one handler can be registered per Lambda execution**. If more than one `MapHandler` is called at runtime, an exception will be thrown. + +This design enables several useful patterns: + +### Use Cases + +**Library-Provided Handlers** + +Libraries can expose pre-configured handlers that applications can opt into: + +```csharp title="MyLibrary.cs" linenums="1" +namespace MyLibrary; + +public static class OrderHandlers +{ + public static void MapOrderHandler(this ILambdaInvocationBuilder app) + { + app.MapHandler(([Event] OrderRequest req, IOrderService orders) => + orders.ProcessAsync(req) + ); + } +} +``` + +```csharp title="Program.cs" linenums="1" +using MyLibrary; + +var builder = LambdaApplication.CreateBuilder(); +builder.Services.AddOrderServices(); // Library-provided services + +var lambda = builder.Build(); + +// Use the library's handler +lambda.MapOrderHandler(); + +await lambda.RunAsync(); +``` + +### Important Notes + +- Only **one** `MapHandler` can execute at runtime—calling multiple will throw an `InvalidOperationException` +- Feature providers are registered when `MapHandler` is called, so ensure the registered handler matches your expected event/response types +- This pattern is designed for **conditional registration**, not for handling multiple event types in a single Lambda (which requires a custom routing solution) + ## Handler Signatures and the `[Event]` Parameter Handlers that receive an incoming payload must identify exactly one parameter with `[Event]`. The generator uses that marker to synthesize deserialization logic (JSON by default, or whatever envelope/serializer is active). If your Lambda does **not** expect input (e.g., scheduled jobs, health checks, etc.), you can omit the `[Event]` attribute entirely—just define a handler with no payload parameter and `AwsLambda.Host` skips the event binding phase. @@ -133,11 +178,15 @@ lambda.MapHandler(async ( `MapHandler` is decorated as a C# 12 interceptor target. During compilation the generator: 1. Ensures the project is built with C# 11+ so interceptors are available (otherwise `LH0004`). -2. Verifies there is exactly one handler and, when a payload parameter exists, exactly one `[Event]` annotation. +2. When a payload parameter exists, verifies exactly one `[Event]` annotation is present. 3. Validates keyed service metadata so the requested key matches the DI container's capabilities (`LH0003` when the key uses an unsupported type such as arrays). 4. Emits a strongly typed `Handle` call that deserializes the payload (if any), resolves services via generated code, sets up features, and serializes the response. -At runtime the stub `MapHandler` method would throw if invoked, but the interception step guarantees that never happens. You get ahead-of-time compatible, reflection-free code with compile-time errors if the signature is invalid. +At runtime: + +- The stub `MapHandler` method would throw if invoked, but the interception step guarantees that never happens +- Only one handler can be registered—calling `MapHandler` multiple times in the same execution throws an `InvalidOperationException` +- You get ahead-of-time compatible, reflection-free code with compile-time errors if the signature is invalid ## Patterns and Best Practices @@ -174,10 +223,6 @@ At runtime the stub `MapHandler` method would throw if invoked, but the intercep ## Troubleshooting -**`LH0001: Multiple handlers registered`** - -Make sure you call `MapHandler` only once. If you need to branch by trigger type, create separate Lambda projects or use envelope dispatching. - **`LH0002: No parameter marked with [Event]`** Add a `[Event]` attribute when your handler accepts an input payload. This diagnostic does **not** appear for payload-less handlers because no event parameter is required in that case. diff --git a/docs/guides/middleware.md b/docs/guides/middleware.md index 19708807..6e1a6eb3 100644 --- a/docs/guides/middleware.md +++ b/docs/guides/middleware.md @@ -121,6 +121,52 @@ Common features: - Handlers remain free of middleware-specific dependencies; they just work with the event/response types. - Custom features are easy to add—register an implementation of `IFeatureProvider` and it becomes available to all middleware. +### Type-Safe Feature Access + +The framework provides convenient extension methods on `ILambdaHostContext` for type-safe event and response access, simplifying the feature access pattern shown above: + +```csharp title="Program.cs" +lambda.UseMiddleware(async (context, next) => +{ + // Nullable access - returns null if not found + var request = context.GetEvent(); + if (request is not null) + Console.WriteLine($"Processing order {request.OrderId}"); + + // Try pattern - safe null checking + if (context.TryGetEvent(out var order)) + { + // Use order safely without additional null checks + Console.WriteLine($"Order {order.OrderId} has {order.Items.Count} items"); + } + + await next(context); + + // Required access - throws if not found + var response = context.GetRequiredResponse(); + Console.WriteLine($"Status: {response.Status}"); +}); +``` + +**Available Methods:** + +| Method | Description | Returns | +|----------------------------|-----------------------------------------|------------------------------------------| +| `GetEvent()` | Returns event or `null` if not found | `T?` | +| `GetResponse()` | Returns response or `null` if not found | `T?` | +| `TryGetEvent(out T)` | Try-pattern for safe event access | `bool` | +| `TryGetResponse(out T)` | Try-pattern for safe response access | `bool` | +| `GetRequiredEvent()` | Returns event or throws | `T` (throws `InvalidOperationException`) | +| `GetRequiredResponse()` | Returns response or throws | `T` (throws `InvalidOperationException`) | + +**When to use each:** + +- **Nullable methods** (`GetEvent()`) – When the event/response might not exist and you'll handle null gracefully +- **Try pattern** (`TryGetEvent()`) – When you want explicit null checking without additional conditionals +- **Required methods** (`GetRequiredEvent()`) – When the event/response must exist and missing it is an error condition + +These methods are equivalent to calling `context.Features.Get>()` and accessing the event/response, but provide cleaner syntax and better null-safety annotations. + ### Feature Providers in Practice When `context.Features.Get()` runs, `AwsLambda.Host` walks through every registered `IFeatureProvider` diff --git a/examples/AwsLambda.Host.Example.HelloWorld/Program.cs b/examples/AwsLambda.Host.Example.HelloWorld/Program.cs index e70d854e..7a1a8799 100644 --- a/examples/AwsLambda.Host.Example.HelloWorld/Program.cs +++ b/examples/AwsLambda.Host.Example.HelloWorld/Program.cs @@ -1,10 +1,7 @@ -#region - +using System; using AwsLambda.Host.Builder; using Microsoft.Extensions.Hosting; -#endregion - // Create the application builder var builder = LambdaApplication.CreateBuilder(); @@ -12,7 +9,13 @@ var lambda = builder.Build(); // Map your handler - the event is automatically injected -lambda.MapHandler(([Event] string name) => $"Hello {name}!"); +lambda.MapHandler( + ([Event] Request request) => new Response($"Hello {request.Name}!", DateTime.UtcNow) +); // Run the Lambda await lambda.RunAsync(); + +internal record Response(string Message, DateTime TimestampUtc); + +internal record Request(string Name); diff --git a/src/AwsLambda.Host.Abstractions/Features/IEventFeatureProviderFactory.cs b/src/AwsLambda.Host.Abstractions/Features/IEventFeatureProviderFactory.cs new file mode 100644 index 00000000..5d56b2fc --- /dev/null +++ b/src/AwsLambda.Host.Abstractions/Features/IEventFeatureProviderFactory.cs @@ -0,0 +1,21 @@ +namespace AwsLambda.Host.Core; + +/// Creates feature providers for Lambda event deserialization. +/// +/// +/// creates +/// instances for specific event types during Lambda invocations. The factory enables +/// lazy registration of event feature providers. This factory is registered automatically +/// at startup. +/// +/// +public interface IEventFeatureProviderFactory +{ + /// Creates a feature provider for the specified event type. + /// The type of event object to create a provider for. + /// + /// An that can create + /// instances for the specified type. + /// + IFeatureProvider Create(); +} diff --git a/src/AwsLambda.Host.Abstractions/Features/IResponseFeatureProviderFactory.cs b/src/AwsLambda.Host.Abstractions/Features/IResponseFeatureProviderFactory.cs new file mode 100644 index 00000000..d742f0bd --- /dev/null +++ b/src/AwsLambda.Host.Abstractions/Features/IResponseFeatureProviderFactory.cs @@ -0,0 +1,21 @@ +namespace AwsLambda.Host.Core; + +/// Creates feature providers for Lambda response serialization. +/// +/// +/// creates +/// instances for specific response types during Lambda invocations. The factory enables +/// lazy registration of response feature providers. This factory is registered automatically +/// at startup. +/// +/// +public interface IResponseFeatureProviderFactory +{ + /// Creates a feature provider for the specified response type. + /// The type of response object to create a provider for. + /// + /// An that can create + /// instances for the specified type. + /// + IFeatureProvider Create(); +} diff --git a/src/AwsLambda.Host.OpenTelemetry/LambdaOpenTelemetryAdapters.cs b/src/AwsLambda.Host.OpenTelemetry/LambdaOpenTelemetryAdapters.cs index 27cc4bb8..3a900d83 100644 --- a/src/AwsLambda.Host.OpenTelemetry/LambdaOpenTelemetryAdapters.cs +++ b/src/AwsLambda.Host.OpenTelemetry/LambdaOpenTelemetryAdapters.cs @@ -52,6 +52,9 @@ public static class LambdaOpenTelemetryServiceProviderExtensions /// , or if a instance is not /// registered in the dependency injection container. /// + [Obsolete( + "This method will be removed in v2.0.0 Use UseOpenTelemetryTracing directly instead." + )] public Func GetOpenTelemetryTracer< TEvent, TResponse @@ -107,6 +110,9 @@ is not TResponse responseT /// Thrown if the context response is not of type /// . /// + [Obsolete( + "This method will be removed in v2.0.0 Use UseOpenTelemetryTracing directly instead." + )] public Func< LambdaInvocationDelegate, LambdaInvocationDelegate @@ -154,6 +160,9 @@ is not TResponse responseT /// Thrown if the context event is not of type /// . /// + [Obsolete( + "This method will be removed in v2.0.0 Use UseOpenTelemetryTracing directly instead." + )] public Func< LambdaInvocationDelegate, LambdaInvocationDelegate @@ -194,6 +203,9 @@ async Task (_, _) => await next(context), /// Neither /// event nor response types are relevant or known when using this overload. /// + [Obsolete( + "This method will be removed in v2.0.0 Use UseOpenTelemetryTracing directly instead." + )] public Func< LambdaInvocationDelegate, LambdaInvocationDelegate diff --git a/src/AwsLambda.Host.OpenTelemetry/MiddlewareOpenTelemetryExtensions.cs b/src/AwsLambda.Host.OpenTelemetry/MiddlewareOpenTelemetryExtensions.cs index 9d1ded2e..995dd42c 100644 --- a/src/AwsLambda.Host.OpenTelemetry/MiddlewareOpenTelemetryExtensions.cs +++ b/src/AwsLambda.Host.OpenTelemetry/MiddlewareOpenTelemetryExtensions.cs @@ -1,5 +1,6 @@ -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; +using AwsLambda.Host.Core; +using Microsoft.Extensions.DependencyInjection; +using OpenTelemetry.Instrumentation.AWSLambda; using OpenTelemetry.Trace; namespace AwsLambda.Host.Builder; @@ -8,83 +9,48 @@ namespace AwsLambda.Host.Builder; /// Provides extension methods for enabling OpenTelemetry tracing in the Lambda invocation /// pipeline. /// -[ExcludeFromCodeCoverage] public static class MiddlewareOpenTelemetryExtensions { - /// Enables OpenTelemetry tracing for the AWS Lambda handler. - /// - /// - /// This method is as a no-op that is intercepted and replaced at compile time It uses the - /// OpenTelemetry instrumentation provided by the - /// OpenTelemetry.Instrumentation.AWSLambda - /// package to instrument the Lambda handler invocations with distributed tracing. - /// - /// - /// When this method is called, the source generator creates an interceptor that: - /// - /// - /// - /// At startup, pulls an instance of from - /// the dependency injection container. This will be used for the lifetime of the - /// Lambda. - /// - /// - /// - /// - /// Wraps the handler pipeline with tracing middleware that creates a - /// root span with invocation info. - /// - /// - /// - /// - /// - /// Middleware Placement: For the most accurate trace data, this method should be - /// called at the top of the middleware pipeline, before other middleware where possible. This - /// ensures that tracing captures as much of the invocation as possible, including the - /// execution time of subsequent middleware components. - /// - /// - /// TracerProvider Registration Required: A instance - /// must be registered in the dependency injection container before calling this method. If no - /// instance is registered, an will be thrown at - /// startup. - /// - /// - /// The instance. - /// The same instance for method chaining. - /// - /// - /// First, register OpenTelemetry in the dependency injection container using AWS Lambda - /// configurations: - /// - /// - /// var builder = LambdaApplication.CreateBuilder(); - /// - /// builder - /// .Services.AddOpenTelemetry() - /// .WithTracing(configure => configure - /// .AddAWSLambdaConfigurations() - /// .AddConsoleExporter()); - /// - /// Then call this method in your Lambda handler setup to enable tracing: - /// - /// var lambda = builder.Build(); - /// - /// lambda.UseOpenTelemetryTracing(); - /// - /// lambda.MapHandler(([Event] Request request) => new Response($"Hello {request.Name}!")); - /// - /// await lambda.RunAsync(); - /// - /// record Request(string Name); - /// record Response(string Message); - /// - /// - public static ILambdaInvocationBuilder UseOpenTelemetryTracing( - this ILambdaInvocationBuilder application - ) + extension(ILambdaInvocationBuilder builder) { - Debug.Fail("This method should have been intercepted at compile time!"); - throw new InvalidOperationException("This method is replaced at compile time."); + /// Enables OpenTelemetry tracing for AWS Lambda handler invocations. + /// + /// + /// Adds middleware that wraps each Lambda invocation with distributed tracing using the + /// from the OpenTelemetry AWS Lambda instrumentation + /// package. A root span is created for each invocation with Lambda context information. + /// + /// + /// Middleware Placement: Call this method early in the middleware pipeline to + /// capture the execution time of all subsequent middleware and handler logic. + /// + /// + /// TracerProvider Registration Required: A must be + /// registered in the dependency injection container. If not found, an + /// is thrown at startup. + /// + /// + /// The same instance for method chaining. + public ILambdaInvocationBuilder UseOpenTelemetryTracing() + { + ArgumentNullException.ThrowIfNull(builder); + + var tracerProvider = builder.Services.GetRequiredService(); + + return builder.Use(next => + context => + AWSLambdaWrapper.TraceAsync( + tracerProvider, + async Task (_, _) => + { + await next(context); + + return context.Features.Get()?.GetResponse(); + }, + context.Features.Get()?.GetEvent(context), + context + ) + ); + } } } diff --git a/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Shipped.md b/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Shipped.md index 2da807aa..53047bfd 100644 --- a/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Shipped.md @@ -7,4 +7,4 @@ LH0001 | AwsLambda.Host.Usage | Error | Multiple method calls detected LH0002 | AwsLambda.Host.Usage | Error | Multiple parameters use attribute LH0003 | AwsLambda.Host.Usage | Error | Invalid attribute argument - LH0004 | AwsLambda.Host.Configuration | Error | C# language version too low \ No newline at end of file + LH0004 | AwsLambda.Host.Configuration | Error | C# language version too low diff --git a/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Unshipped.md b/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Unshipped.md index 8b137891..a4c46e3b 100644 --- a/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Unshipped.md +++ b/src/AwsLambda.Host.SourceGenerators/AnalyzerReleases.Unshipped.md @@ -1 +1,5 @@ +### Removed Rules + Rule ID | Category | Severity | Notes +---------|------------------------------|----------|----------------------------------- + LH0001 | AwsLambda.Host.Usage | Error | Multiple method calls detected \ No newline at end of file diff --git a/src/AwsLambda.Host.SourceGenerators/Diagnostics/DiagnosticGenerator.cs b/src/AwsLambda.Host.SourceGenerators/Diagnostics/DiagnosticGenerator.cs index d2c9d6bd..3af20531 100644 --- a/src/AwsLambda.Host.SourceGenerators/Diagnostics/DiagnosticGenerator.cs +++ b/src/AwsLambda.Host.SourceGenerators/Diagnostics/DiagnosticGenerator.cs @@ -14,18 +14,6 @@ internal static List GenerateDiagnostics(CompilationInfo compilation var delegateInfos = compilationInfo.MapHandlerInvocationInfos; - // check for multiple invocations of MapHandler - if (delegateInfos.Count > 1) - diagnostics.AddRange( - delegateInfos.Select(invocationInfo => - Diagnostic.Create( - Diagnostics.MultipleMethodCalls, - invocationInfo.LocationInfo?.ToLocation(), - "LambdaApplication.MapHandler(Delegate)" - ) - ) - ); - // Validate parameters foreach (var invocationInfo in delegateInfos) // check for multiple parameters that use the `[Event]` attribute diff --git a/src/AwsLambda.Host.SourceGenerators/Diagnostics/Diagnostics.cs b/src/AwsLambda.Host.SourceGenerators/Diagnostics/Diagnostics.cs index 57e7a965..09a11819 100644 --- a/src/AwsLambda.Host.SourceGenerators/Diagnostics/Diagnostics.cs +++ b/src/AwsLambda.Host.SourceGenerators/Diagnostics/Diagnostics.cs @@ -7,15 +7,6 @@ internal static class Diagnostics private const string UsageCategory = "AwsLambda.Host.Usage"; private const string ConfigurationCategory = "AwsLambda.Host.Configuration"; - internal static readonly DiagnosticDescriptor MultipleMethodCalls = new( - "LH0001", - "Multiple method calls detected", - "Method '{0}' can only be invoked once per project. Remove this duplicate invocation.", - UsageCategory, - DiagnosticSeverity.Error, - true - ); - internal static readonly DiagnosticDescriptor MultipleParametersUseAttribute = new( "LH0002", "Multiple parameters use attribute", diff --git a/src/AwsLambda.Host.SourceGenerators/OutputGenerators/LambdaHostOutputGenerator.cs b/src/AwsLambda.Host.SourceGenerators/OutputGenerators/LambdaHostOutputGenerator.cs index 0aadd8bb..94befc1c 100644 --- a/src/AwsLambda.Host.SourceGenerators/OutputGenerators/LambdaHostOutputGenerator.cs +++ b/src/AwsLambda.Host.SourceGenerators/OutputGenerators/LambdaHostOutputGenerator.cs @@ -19,7 +19,10 @@ string generatorVersion if (diagnostics.Any()) { diagnostics.ForEach(context.ReportDiagnostic); - return; + + // if there are any errors, return without generating any source code. + if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error)) + return; } // create GeneratedCodeAttribute. This is used across all generated source files. @@ -28,30 +31,28 @@ string generatorVersion List outputs = [CommonSources.Generate(generatedCodeAttribute)]; - // if MapHandler calls found, generate the source code. Will always be 0 or 1 at this point. - // Anything that needs to know types from the handler must be generated here. - if (compilationInfo.MapHandlerInvocationInfos.Count(x => x.Name != "Handle") == 1) - { - var mapHandlerInvocationInfo = compilationInfo.MapHandlerInvocationInfos.First(); - + // if MapHandler calls found, generate the source code. + if (compilationInfo.MapHandlerInvocationInfos.Count >= 1) outputs.Add( MapHandlerSources.Generate( - mapHandlerInvocationInfo, + compilationInfo.MapHandlerInvocationInfos, compilationInfo.BuilderInfos, generatedCodeAttribute ) ); - // if UseOpenTelemetryTracing calls found, generate the source code. - if (compilationInfo.UseOpenTelemetryTracingInfos.Count >= 1) - outputs.Add( - OpenTelemetrySources.Generate( - compilationInfo.UseOpenTelemetryTracingInfos, - mapHandlerInvocationInfo.DelegateInfo, - generatedCodeAttribute - ) - ); - } + // add OnInit interceptors + if (compilationInfo.OnInitInvocationInfos.Count >= 1) + outputs.Add( + GenericHandlerSources.Generate( + compilationInfo.OnInitInvocationInfos, + "OnInit", + "bool", + "true", + "ILambdaOnInitBuilder", + generatedCodeAttribute + ) + ); // add OnShutdown interceptors if (compilationInfo.OnShutdownInvocationInfos.Count >= 1) @@ -66,19 +67,6 @@ string generatorVersion ) ); - // add OnInit interceptors - if (compilationInfo.OnInitInvocationInfos.Count >= 1) - outputs.Add( - GenericHandlerSources.Generate( - compilationInfo.OnInitInvocationInfos, - "OnInit", - "bool", - "true", - "ILambdaOnInitBuilder", - generatedCodeAttribute - ) - ); - // join all the source code together and add it to the compilation context. var outCode = string.Join("\n", outputs.Where(s => s != null)); diff --git a/src/AwsLambda.Host.SourceGenerators/OutputGenerators/MapHandlerSources.cs b/src/AwsLambda.Host.SourceGenerators/OutputGenerators/MapHandlerSources.cs index 2288bd66..472795b4 100644 --- a/src/AwsLambda.Host.SourceGenerators/OutputGenerators/MapHandlerSources.cs +++ b/src/AwsLambda.Host.SourceGenerators/OutputGenerators/MapHandlerSources.cs @@ -8,63 +8,75 @@ namespace AwsLambda.Host.SourceGenerators; internal static class MapHandlerSources { internal static string Generate( - HigherOrderMethodInfo higherOrderMethodInfo, + EquatableArray mapHandlerInvocationInfos, EquatableArray builderInfo, string generatedCodeAttribute ) { - var delegateInfo = higherOrderMethodInfo.DelegateInfo; + var mapHandlerCalls = mapHandlerInvocationInfos.Select(mapHandlerInvocationInfo => + { + var delegateInfo = mapHandlerInvocationInfo.DelegateInfo; - // build handler function signature - var handlerSignature = delegateInfo.BuildHandlerSignature(); + // build handler function signature + var handlerSignature = delegateInfo.BuildHandlerSignature(); - // build out assignment statements for each handler parameter - var handlerArgs = delegateInfo.BuildHandlerParameterAssignment(); + // build out assignment statements for each handler parameter + var handlerArgs = delegateInfo.BuildHandlerParameterAssignment(); - // get input event type - var inputEvent = delegateInfo.EventParameter is { } p - ? new - { - IsStream = p.TypeInfo.FullyQualifiedType == TypeConstants.Stream, - Type = p.TypeInfo.FullyQualifiedType, - } - : null; + // get input event type + var inputEvent = delegateInfo.EventParameter is { } p + ? new + { + IsStream = p.TypeInfo.FullyQualifiedType == TypeConstants.Stream, + Type = p.TypeInfo.FullyQualifiedType, + } + : null; + + // get output response type and whether it is a stream + var outputResponse = delegateInfo.HasResponse + ? new + { + ResponseType = delegateInfo.ReturnTypeInfo.UnwrappedFullyQualifiedType, + ResponseIsStream = delegateInfo.ReturnTypeInfo.UnwrappedFullyQualifiedType + == TypeConstants.Stream, + } + : null; - // get output response type and whether it is a stream - var outputResponse = delegateInfo.HasResponse - ? new - { - ResponseType = delegateInfo.ReturnTypeInfo.UnwrappedFullyQualifiedType, - ResponseIsStream = delegateInfo.ReturnTypeInfo.UnwrappedFullyQualifiedType - == TypeConstants.Stream, - } - : null; + // determine if event feature is required + var isEventFeatureRequired = inputEvent is { IsStream: false }; - var builderCalls = builderInfo.Select(b => b.InterceptableLocationInfo).ToArray(); + // determine if response feature is required + var isResponseFeatureRequired = outputResponse is { ResponseIsStream: false }; - var model = new - { - Location = higherOrderMethodInfo.InterceptableLocationInfo, - HandlerSignature = handlerSignature, - delegateInfo.HasAnyKeyedServiceParameter, - HandlerArgs = handlerArgs, - ShouldAwait = delegateInfo.IsAwaitable, - InputEvent = inputEvent, - OutputResponse = outputResponse, - Builders = builderCalls, - GeneratedCodeAttribute = generatedCodeAttribute, - }; + return new + { + Location = mapHandlerInvocationInfo.InterceptableLocationInfo, + HandlerSignature = handlerSignature, + IsEventFeatureRequired = isEventFeatureRequired, + IsResponseFeatureRequired = isResponseFeatureRequired, + delegateInfo.HasAnyKeyedServiceParameter, + HandlerArgs = handlerArgs, + ShouldAwait = delegateInfo.IsAwaitable, + InputEvent = inputEvent, + OutputResponse = outputResponse, + }; + }); var template = TemplateHelper.LoadTemplate( GeneratorConstants.LambdaHostMapHandlerExtensionsTemplateFile ); - return template.Render(model); + return template.Render( + new + { + GeneratedCodeAttribute = generatedCodeAttribute, + MapHandlerCalls = mapHandlerCalls, + } + ); } - private static HandlerArg[] BuildHandlerParameterAssignment(this DelegateInfo delegateInfo) - { - var handlerArgs = delegateInfo + private static HandlerArg[] BuildHandlerParameterAssignment(this DelegateInfo delegateInfo) => + delegateInfo .Parameters.Select(param => new HandlerArg { String = param.ToPublicString(), @@ -103,8 +115,5 @@ private static HandlerArg[] BuildHandlerParameterAssignment(this DelegateInfo de }) .ToArray(); - return handlerArgs; - } - private readonly record struct HandlerArg(string String, string Assignment); } diff --git a/src/AwsLambda.Host.SourceGenerators/README.md b/src/AwsLambda.Host.SourceGenerators/README.md new file mode 100644 index 00000000..94287259 --- /dev/null +++ b/src/AwsLambda.Host.SourceGenerators/README.md @@ -0,0 +1,7 @@ +# AwsLambda.Host.SourceGenerators + +## Notes + +### `AnalyzerReleases.Shipped` and` AnalyzerReleases.Unshipped` + +https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md diff --git a/src/AwsLambda.Host.SourceGenerators/SyntaxProviders/MapHandlerSyntaxProvider.cs b/src/AwsLambda.Host.SourceGenerators/SyntaxProviders/MapHandlerSyntaxProvider.cs index a5386326..c280754c 100644 --- a/src/AwsLambda.Host.SourceGenerators/SyntaxProviders/MapHandlerSyntaxProvider.cs +++ b/src/AwsLambda.Host.SourceGenerators/SyntaxProviders/MapHandlerSyntaxProvider.cs @@ -7,7 +7,7 @@ namespace AwsLambda.Host.SourceGenerators; internal static class MapHandlerSyntaxProvider { internal static bool Predicate(SyntaxNode node, CancellationToken cancellationToken) => - HandlerInfoExtractor.Predicate(node, GeneratorConstants.MapHandlerMethodName, "Handle"); + HandlerInfoExtractor.Predicate(node, GeneratorConstants.MapHandlerMethodName); internal static HigherOrderMethodInfo? Transformer( GeneratorSyntaxContext context, diff --git a/src/AwsLambda.Host.SourceGenerators/Templates/GenericHandler.scriban b/src/AwsLambda.Host.SourceGenerators/Templates/GenericHandler.scriban index 1cfd8746..949c29dc 100644 --- a/src/AwsLambda.Host.SourceGenerators/Templates/GenericHandler.scriban +++ b/src/AwsLambda.Host.SourceGenerators/Templates/GenericHandler.scriban @@ -7,10 +7,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; {{ generated_code_attribute }} - file static class {{ name }}LambdaApplicationExtensions + file static class GeneratedLambda{{ name }}BuilderExtensions { {{~ for call in calls ~}} // Location: {{ call.location.display_location }} diff --git a/src/AwsLambda.Host.SourceGenerators/Templates/MapHandler.scriban b/src/AwsLambda.Host.SourceGenerators/Templates/MapHandler.scriban index 66857a42..d60d1c94 100644 --- a/src/AwsLambda.Host.SourceGenerators/Templates/MapHandler.scriban +++ b/src/AwsLambda.Host.SourceGenerators/Templates/MapHandler.scriban @@ -2,72 +2,75 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; {{ generated_code_attribute }} - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { - // Location: {{ location.display_location }} - [InterceptsLocation({{ location.version }}, "{{ location.data }}")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + + {{~ for call in map_handler_calls ~}} + // Location: {{ call.location.display_location }} + [InterceptsLocation({{ call.location.version }}, "{{ call.location.data }}")] + internal static ILambdaInvocationBuilder MapHandlerInterceptor{{ for.index }}( this ILambdaInvocationBuilder application, Delegate handler ) { - var castHandler = ({{ handler_signature }})handler; - - return application.Handle(InvocationDelegate); + var castHandler = ({{ call.handler_signature }})handler; + + application.Handle(InvocationDelegate); + {{~ if call.is_event_feature_required ~}} + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create<{{ call.input_event.type }}>(); + {{~ end ~}} + {{~ if call.is_response_feature_required ~}} + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create<{{ call.output_response.response_type }}>(); + {{~ end ~}} + + return application; - {{ if should_await ~}} async {{ end ~}}Task InvocationDelegate(ILambdaHostContext context) + {{ if call.should_await ~}} async {{ end ~}}Task InvocationDelegate(ILambdaHostContext context) { - {{~ if has_any_keyed_service_parameter ~}} + {{~ if call.has_any_keyed_service_parameter ~}} if (context.ServiceProvider.GetService() is not IServiceProviderIsKeyedService) { throw new InvalidOperationException($"Unable to resolve service referenced by {nameof(FromKeyedServicesAttribute)}. The service provider doesn't support keyed services."); } {{~ end ~}} - {{~ for handler_arg in handler_args ~}} + {{~ for handler_arg in call.handler_args ~}} // {{ handler_arg.string }} var arg{{ for.index }} = {{ handler_arg.assignment }}; {{~ end ~}} - {{ if output_response != null; ~}} var response = {{ end }}{{ if should_await ~}} await {{ end ~}} castHandler.Invoke({{ for arg in handler_args }}arg{{ for.index }}{{ if !for.last }}, {{ end }}{{ end }}); - {{~ if output_response != null; ~}} - {{~ if output_response.response_is_stream ~}} + {{ if call.output_response != null; ~}} var response = {{ end }}{{ if call.should_await ~}} await {{ end ~}} castHandler.Invoke({{ for arg in call.handler_args }}arg{{ for.index }}{{ if !for.last }}, {{ end }}{{ end }}); + {{~ if call.output_response != null; ~}} + {{~ if call.output_response.response_is_stream ~}} context.Features.GetRequired().ResponseStream = response; {{~ else ~}} - if (context.Features.Get() is not IResponseFeature<{{ output_response.response_type }}> responseFeature) + if (context.Features.Get() is not IResponseFeature<{{ call.output_response.response_type }}> responseFeature) { - throw new InvalidOperationException($"Response feature for type '{{ output_response.response_type }}' is not available in the collection."); + throw new InvalidOperationException($"Response feature for type '{{ call.output_response.response_type }}' is not available in the collection."); } responseFeature.SetResponse(response); {{~ end ~}} {{~ end ~}} - {{~ if !should_await ~}} + {{~ if !call.should_await ~}} return Task.CompletedTask; {{~ end ~}} } } - {{~ if builders.size >= 1 ~}} - - {{~ for builder in builders ~}} - [InterceptsLocation({{ builder.version }}, "{{ builder.data }}")] // Location: {{ builder.display_location }} - {{~ end ~}} - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - {{~ if input_event != null && !input_event.is_stream ~}} - builder.Services.AddSingleton>(); - {{~ end ~}} - {{~ if output_response != null && !output_response.response_is_stream ~}} - builder.Services.AddSingleton>(); - {{~ end ~}} - return builder.Build(); - } {{~ end ~}} } } diff --git a/src/AwsLambda.Host.SourceGenerators/Templates/OpenTelemetry.scriban b/src/AwsLambda.Host.SourceGenerators/Templates/OpenTelemetry.scriban deleted file mode 100644 index 5f70b754..00000000 --- a/src/AwsLambda.Host.SourceGenerators/Templates/OpenTelemetry.scriban +++ /dev/null @@ -1,30 +0,0 @@ -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - {{ generated_code_attribute }} - file static class OpenTelemetryLambdaApplicationExtensions - { - {{~ for location in locations ~}} - [InterceptsLocation({{ location.version }}, "{{ location.data }}")] // Location: {{ location.display_location }} - {{~ end ~}} - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - {{~ if response_type != null && event_type != null ~}} - return application.Use(application.Services.GetOpenTelemetryTracer<{{ event_type }}, {{ response_type }}>()); - {{~ else if response_type != null ~}} - return application.Use(application.Services.GetOpenTelemetryTracerNoEvent<{{ response_type }}>()); - {{~ else if event_type != null ~}} - return application.Use(application.Services.GetOpenTelemetryTracerNoResponse<{{ event_type }}>()); - {{~ else ~}} - return application.Use(application.Services.GetOpenTelemetryTracerNoEventNoResponse()); - {{~ end ~}} - } - } -} diff --git a/src/AwsLambda.Host/Builder/Extensions/ServiceCollectionExtensions.cs b/src/AwsLambda.Host/Builder/Extensions/ServiceCollectionExtensions.cs index fc8313e2..ec5fa000 100644 --- a/src/AwsLambda.Host/Builder/Extensions/ServiceCollectionExtensions.cs +++ b/src/AwsLambda.Host/Builder/Extensions/ServiceCollectionExtensions.cs @@ -48,6 +48,13 @@ public IServiceCollection AddLambdaHostCoreServices() EnvelopeOptionsPostConfiguration >(); + // Register IFeatureProvider factories + services.AddSingleton< + IResponseFeatureProviderFactory, + ResponseFeatureProviderFactory + >(); + services.AddSingleton(); + return services; } diff --git a/src/AwsLambda.Host/Builder/LambdaInvocationBuilder.cs b/src/AwsLambda.Host/Builder/LambdaInvocationBuilder.cs index 1660da93..a413c149 100644 --- a/src/AwsLambda.Host/Builder/LambdaInvocationBuilder.cs +++ b/src/AwsLambda.Host/Builder/LambdaInvocationBuilder.cs @@ -2,6 +2,9 @@ namespace AwsLambda.Host.Builder; internal class LambdaInvocationBuilder : ILambdaInvocationBuilder { + internal const string EventFeatureProviderKey = "__EventFeatureProvider"; + internal const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + private readonly List> _middleware = []; diff --git a/src/AwsLambda.Host/Core/Context/LambdaHostContextFactory.cs b/src/AwsLambda.Host/Core/Context/LambdaHostContextFactory.cs index 9448b21b..bf8505fa 100644 --- a/src/AwsLambda.Host/Core/Context/LambdaHostContextFactory.cs +++ b/src/AwsLambda.Host/Core/Context/LambdaHostContextFactory.cs @@ -8,6 +8,7 @@ internal class LambdaHostContextFactory : ILambdaHostContextFactory private readonly ILambdaHostContextAccessor? _contextAccessor; private readonly IFeatureCollectionFactory _featureCollectionFactory; private readonly IServiceScopeFactory _serviceScopeFactory; + private IFeatureProvider[]? _featureProviders; public LambdaHostContextFactory( IServiceScopeFactory serviceScopeFactory, @@ -29,11 +30,13 @@ public ILambdaHostContext Create( CancellationToken cancellationToken ) { + _featureProviders ??= CreateFeatureProviders(properties); + var context = new DefaultLambdaHostContext( lambdaContext, _serviceScopeFactory, properties, - _featureCollectionFactory.Create(), + _featureCollectionFactory.Create(_featureProviders), cancellationToken ); @@ -41,4 +44,26 @@ CancellationToken cancellationToken return context; } + + private static IFeatureProvider[] CreateFeatureProviders( + IDictionary properties + ) + { + var list = new List(2); + + AddIfPresent(properties, LambdaInvocationBuilder.EventFeatureProviderKey, list); + AddIfPresent(properties, LambdaInvocationBuilder.ResponseFeatureProviderKey, list); + + return list.ToArray(); + } + + private static void AddIfPresent( + IDictionary properties, + string key, + List target + ) + { + if (properties.TryGetValue(key, out var value) && value is IFeatureProvider provider) + target.Add(provider); + } } diff --git a/src/AwsLambda.Host/Core/Features/DefaultEventFeatureProvider.cs b/src/AwsLambda.Host/Core/Features/DefaultEventFeatureProvider.cs index 14bd921e..65085640 100644 --- a/src/AwsLambda.Host/Core/Features/DefaultEventFeatureProvider.cs +++ b/src/AwsLambda.Host/Core/Features/DefaultEventFeatureProvider.cs @@ -7,7 +7,7 @@ namespace AwsLambda.Host.Core; /// deserialization. This provider is instantiated by source-generated code to handle Lambda event /// processing using the specified . /// -public class DefaultEventFeatureProvider(ILambdaSerializer lambdaSerializer) : IFeatureProvider +internal class DefaultEventFeatureProvider(ILambdaSerializer lambdaSerializer) : IFeatureProvider { // ReSharper disable once StaticMemberInGenericType private static readonly Type FeatureType = typeof(IEventFeature); diff --git a/src/AwsLambda.Host/Core/Features/DefaultFeatureCollectionFactory.cs b/src/AwsLambda.Host/Core/Features/DefaultFeatureCollectionFactory.cs index e86fe504..ec634ac7 100644 --- a/src/AwsLambda.Host/Core/Features/DefaultFeatureCollectionFactory.cs +++ b/src/AwsLambda.Host/Core/Features/DefaultFeatureCollectionFactory.cs @@ -1,7 +1,8 @@ namespace AwsLambda.Host.Core; -internal class DefaultFeatureCollectionFactory(IEnumerable featureProviders) +internal class DefaultFeatureCollectionFactory(IEnumerable providers) : IFeatureCollectionFactory { - public IFeatureCollection Create() => new DefaultFeatureCollection(featureProviders); + public IFeatureCollection Create(IEnumerable featureProviders) => + new DefaultFeatureCollection(providers.Concat(featureProviders).ToArray()); } diff --git a/src/AwsLambda.Host/Core/Features/DefaultResponseFeatureProvider.cs b/src/AwsLambda.Host/Core/Features/DefaultResponseFeatureProvider.cs index 26e6ec73..73e74ee6 100644 --- a/src/AwsLambda.Host/Core/Features/DefaultResponseFeatureProvider.cs +++ b/src/AwsLambda.Host/Core/Features/DefaultResponseFeatureProvider.cs @@ -7,7 +7,7 @@ namespace AwsLambda.Host.Core; /// serialization. This provider is instantiated by source-generated code to handle Lambda response /// processing using the specified . /// -public class DefaultResponseFeatureProvider(ILambdaSerializer lambdaSerializer) +internal class DefaultResponseFeatureProvider(ILambdaSerializer lambdaSerializer) : IFeatureProvider { // ReSharper disable once StaticMemberInGenericType diff --git a/src/AwsLambda.Host/Core/Features/EventFeatureProviderFactory.cs b/src/AwsLambda.Host/Core/Features/EventFeatureProviderFactory.cs new file mode 100644 index 00000000..39b16364 --- /dev/null +++ b/src/AwsLambda.Host/Core/Features/EventFeatureProviderFactory.cs @@ -0,0 +1,9 @@ +using Amazon.Lambda.Core; + +namespace AwsLambda.Host.Core; + +internal class EventFeatureProviderFactory(ILambdaSerializer lambdaSerializer) + : IEventFeatureProviderFactory +{ + public IFeatureProvider Create() => new DefaultEventFeatureProvider(lambdaSerializer); +} diff --git a/src/AwsLambda.Host/Core/Features/IFeatureCollectionFactory.cs b/src/AwsLambda.Host/Core/Features/IFeatureCollectionFactory.cs index 84497607..d2db74ba 100644 --- a/src/AwsLambda.Host/Core/Features/IFeatureCollectionFactory.cs +++ b/src/AwsLambda.Host/Core/Features/IFeatureCollectionFactory.cs @@ -2,5 +2,5 @@ namespace AwsLambda.Host.Core; internal interface IFeatureCollectionFactory { - IFeatureCollection Create(); + IFeatureCollection Create(IEnumerable featureProviders); } diff --git a/src/AwsLambda.Host/Core/Features/ResponseFeatureProviderFactory.cs b/src/AwsLambda.Host/Core/Features/ResponseFeatureProviderFactory.cs new file mode 100644 index 00000000..6196a355 --- /dev/null +++ b/src/AwsLambda.Host/Core/Features/ResponseFeatureProviderFactory.cs @@ -0,0 +1,9 @@ +using Amazon.Lambda.Core; + +namespace AwsLambda.Host.Core; + +internal class ResponseFeatureProviderFactory(ILambdaSerializer lambdaSerializer) + : IResponseFeatureProviderFactory +{ + public IFeatureProvider Create() => new DefaultResponseFeatureProvider(lambdaSerializer); +} diff --git a/tests/AwsLambda.Host.OpenTelemetry.UnitTests/LambdaOpenTelemetryServiceProviderExtensionsTests.cs b/tests/AwsLambda.Host.OpenTelemetry.UnitTests/LambdaOpenTelemetryServiceProviderExtensionsTests.cs index 9e02d27f..f62c038f 100644 --- a/tests/AwsLambda.Host.OpenTelemetry.UnitTests/LambdaOpenTelemetryServiceProviderExtensionsTests.cs +++ b/tests/AwsLambda.Host.OpenTelemetry.UnitTests/LambdaOpenTelemetryServiceProviderExtensionsTests.cs @@ -1,4 +1,4 @@ -using AwsLambda.Host.UnitTests; +using AwsLambda.Host.UnitTests; using Microsoft.Extensions.DependencyInjection; using OpenTelemetry.Trace; diff --git a/tests/AwsLambda.Host.OpenTelemetry.UnitTests/MiddlewareOpenTelemetryExtensionsTest.cs b/tests/AwsLambda.Host.OpenTelemetry.UnitTests/MiddlewareOpenTelemetryExtensionsTest.cs new file mode 100644 index 00000000..f5b4e94a --- /dev/null +++ b/tests/AwsLambda.Host.OpenTelemetry.UnitTests/MiddlewareOpenTelemetryExtensionsTest.cs @@ -0,0 +1,117 @@ +using AwsLambda.Host.UnitTests; +using OpenTelemetry.Trace; + +namespace AwsLambda.Host.OpenTelemetry.UnitTests; + +[TestSubject(typeof(MiddlewareOpenTelemetryExtensions))] +public class MiddlewareOpenTelemetryExtensionsTest +{ + [Fact] + public void UseOpenTelemetryTracing_WithNullBuilder_ThrowsArgumentNullException() + { + // Arrange + ILambdaInvocationBuilder builder = null!; + + // Act + Action act = () => builder.UseOpenTelemetryTracing(); + + // Assert + act.Should().ThrowExactly(); + } + + [Theory] + [AutoNSubstituteData] + public void UseOpenTelemetryTracing_WithNoTracerProvider_ThrowsInvalidOperationException( + [Frozen] IServiceProvider serviceProvider, + ILambdaInvocationBuilder builder + ) + { + // Arrange + serviceProvider.GetService(typeof(TracerProvider)).Returns(null); + builder.Services.Returns(serviceProvider); + + // Act + Action act = () => builder.UseOpenTelemetryTracing(); + + // Assert + act.Should() + .ThrowExactly() + .WithMessage( + "No service for type 'OpenTelemetry.Trace.TracerProvider' has been registered." + ); + } + + [Theory] + [AutoNSubstituteData] + public void UseOpenTelemetryTracing_RegistersMiddleware_AndReturnsBuilder( + [Frozen] IServiceProvider serviceProvider, + [Frozen] ILambdaInvocationBuilder builder, + TracerProvider tracerProvider + ) + { + // Arrange + serviceProvider.GetService(typeof(TracerProvider)).Returns(tracerProvider); + builder.Services.Returns(serviceProvider); + builder + .Use(Arg.Any>()) + .Returns(builder); + + // Act + var result = builder.UseOpenTelemetryTracing(); + + // Assert + result.Should().Be(builder); + builder + .Received(1) + .Use(Arg.Any>()); + } + + [Theory] + [AutoNSubstituteData] + public async Task UseOpenTelemetryTracing_Middleware_CallsNextDelegate( + [Frozen] IServiceProvider serviceProvider, + [Frozen] ILambdaInvocationBuilder builder, + TracerProvider tracerProvider, + ILambdaHostContext context, + IFeatureCollection features + ) + { + // Arrange + Func? capturedMiddleware = null; + + serviceProvider.GetService(typeof(TracerProvider)).Returns(tracerProvider); + builder.Services.Returns(serviceProvider); + builder + .Use( + Arg.Do>(m => + capturedMiddleware = m + ) + ) + .Returns(builder); + + context.Features.Returns(features); + features.Get().Returns((IEventFeature?)null); + features.Get().Returns((IResponseFeature?)null); + + // Act + builder.UseOpenTelemetryTracing(); + + // Assert - middleware was captured + capturedMiddleware.Should().NotBeNull(); + + // Create a mock next delegate to verify it gets called + var nextWasCalled = false; + LambdaInvocationDelegate next = _ => + { + nextWasCalled = true; + return Task.CompletedTask; + }; + + // Execute the captured middleware + var wrappedDelegate = capturedMiddleware!(next); + await wrappedDelegate(context); + + // Verify the next delegate was called (wrapped by AWSLambdaWrapper.TraceAsync) + nextWasCalled.Should().BeTrue(); + } +} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/DiagnosticTests.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/DiagnosticTests.cs index 0665395f..2f289aed 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/DiagnosticTests.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/DiagnosticTests.cs @@ -50,13 +50,7 @@ public void Test_MultipleMapHandlersFound() """ ); - diagnostics.Length.Should().Be(2); - - foreach (var diagnostic in diagnostics) - { - diagnostic.Id.Should().Be("LH0001"); - diagnostic.Severity.Should().Be(DiagnosticSeverity.Error); - } + diagnostics.Length.Should().Be(0); } [Fact] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/GeneratorTestHelpers.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/GeneratorTestHelpers.cs index 59435666..8b283f9f 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/GeneratorTestHelpers.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/GeneratorTestHelpers.cs @@ -88,9 +88,6 @@ .. Net90.References.All.ToList(), MetadataReference.CreateFromFile(typeof(IOptions<>).Assembly.Location), MetadataReference.CreateFromFile(typeof(ILambdaHostContext).Assembly.Location), MetadataReference.CreateFromFile(typeof(APIGatewayProxyResponse).Assembly.Location), - MetadataReference.CreateFromFile( - typeof(LambdaOpenTelemetryServiceProviderExtensions).Assembly.Location - ), ]; var compilationOptions = new CSharpCompilationOptions( diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_AllInputSources#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_AllInputSources#LambdaHandler.g.verified.cs index 5ad4c776..9bec200a 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_AllInputSources#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_AllInputSources#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(14,8) [InterceptsLocation(1, "wCxh64raLv7JZxUcekz6bkIBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -76,12 +84,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "wCxh64raLv7JZxUcekz6bgcBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(10,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_Async_ReturnTaskString_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_Async_ReturnTaskString_TypeCast#LambdaHandler.g.verified.cs index c4a39b12..2822f220 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_Async_ReturnTaskString_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_Async_ReturnTaskString_TypeCast#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "52YQ/UddFuGQH5asNzsp/L0AAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -62,12 +70,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "52YQ/UddFuGQH5asNzsp/KwAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoReturn_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoReturn_TypeCast#LambdaHandler.g.verified.cs index c2e41cee..3d363f12 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoReturn_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoReturn_TypeCast#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "24NtoO22UPa+/C0ogM3RV+EAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -62,12 +70,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "24NtoO22UPa+/C0ogM3RV9AAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoTypeInfo_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoTypeInfo_TypeCast#LambdaHandler.g.verified.cs index 379207e4..6c37b765 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoTypeInfo_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_NoTypeInfo_TypeCast#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "jx1Tqmn1fJ3pftRGtSvbSsMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,12 +75,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "jx1Tqmn1fJ3pftRGtSvbSrIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnExplicitType#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnExplicitType#LambdaHandler.g.verified.cs index 5cd3b6b1..447689f9 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnExplicitType#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnExplicitType#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "kmm35a5GJaoqey+0CeV8vdMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,13 +80,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "kmm35a5GJaoqey+0CeV8vcIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnImplicitNullable#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnImplicitNullable#LambdaHandler.g.verified.cs index 4ffd7dc5..0410bb7b 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnImplicitNullable#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnImplicitNullable#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "qgvWtxWrBmeBTRBtlT5A2LUAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,13 +80,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "qgvWtxWrBmeBTRBtlT5A2KQAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnString#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnString#LambdaHandler.g.verified.cs index f00fc235..e2ca8757 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnString#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnString#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "SBl4e782DgMu+0FLfrzfUbUAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -65,13 +78,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "SBl4e782DgMu+0FLfrzfUaQAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnTaskString#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnTaskString#LambdaHandler.g.verified.cs index 9366ece8..b51ae0fc 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnTaskString#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnTaskString#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(12,8) [InterceptsLocation(1, "62ICm9hMTMkVRHJf7bEM0v4AAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -62,12 +70,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "62ICm9hMTMkVRHJf7bEM0sMAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnsTask_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnsTask_TypeCast#LambdaHandler.g.verified.cs index f178eeaf..f75bd5b0 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnsTask_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_ReturnsTask_TypeCast#LambdaHandler.g.verified.cs @@ -30,38 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "hQoB+WlSjNRKx1YwYlKZW70AAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { await castHandler.Invoke(); } } - - [InterceptsLocation(1, "hQoB+WlSjNRKx1YwYlKZW6wAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_StreamResponse#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_StreamResponse#LambdaHandler.g.verified.cs index b2436e87..d39dfe67 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_StreamResponse#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_StreamResponse#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "6HO/UYhbMUo2aMF5OFFj3scAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -59,11 +62,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "6HO/UYhbMUo2aMF5OFFj3rYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast#LambdaHandler.g.verified.cs index c8671a94..15af876e 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "0swNLwUGxn6gmcAxLw2VYcMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -65,12 +73,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "0swNLwUGxn6gmcAxLw2VYbIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast_InputFromKeyedServices#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast_InputFromKeyedServices#LambdaHandler.g.verified.cs index 95b4c572..ae5c5d4c 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast_InputFromKeyedServices#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/BlockLambdaVerifyTests.Test_BlockLambda_TypeCast_InputFromKeyedServices#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(11,8) [InterceptsLocation(1, "Uxt0NUyaj58kybSiao2f8REBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -69,12 +77,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "Uxt0NUyaj58kybSiao2f8QABAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationToken#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationToken#LambdaHandler.g.verified.cs index 0e7df351..91c2af82 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationToken#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationToken#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "IG1FKecgSQVVqxQ3PHQPeM0AAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -65,12 +73,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "IG1FKecgSQVVqxQ3PHQPeLwAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaContext#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaContext#LambdaHandler.g.verified.cs index ccea80d9..3c4fe28d 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaContext#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaContext#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "wn/8VnbL6/5enHoptgINB+cAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,12 +75,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "wn/8VnbL6/5enHoptgINB9YAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaHostContext#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaHostContext#LambdaHandler.g.verified.cs index 14ff336e..99f4180c 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaHostContext#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_AsksForCancellationTokenAndLambdaHostContext#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "f2st4QpM87EqtO+5cVLplOcAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,12 +75,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "f2st4QpM87EqtO+5cVLplNYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_Async_ReturnExplicitTask#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_Async_ReturnExplicitTask#LambdaHandler.g.verified.cs index 4ab65507..cb67dd68 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_Async_ReturnExplicitTask#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_Async_ReturnExplicitTask#LambdaHandler.g.verified.cs @@ -30,38 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "cms2w+IHinDN9XOT4+diatMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { await castHandler.Invoke(); } } - - [InterceptsLocation(1, "cms2w+IHinDN9XOT4+diasIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ComplexInput_ComplexOutput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ComplexInput_ComplexOutput#LambdaHandler.g.verified.cs index 01400d19..1f5e12be 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ComplexInput_ComplexOutput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ComplexInput_ComplexOutput#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "YAIayk0naS2HI+NqiUzlmO0AAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -68,13 +81,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "YAIayk0naS2HI+NqiUzlmNwAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ExplicitVoid#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ExplicitVoid#LambdaHandler.g.verified.cs index 54625ed8..b9127749 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ExplicitVoid#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ExplicitVoid#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(11,8) [InterceptsLocation(1, "S8za7TGX8LSwYna0cXthvuAAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -58,11 +61,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "S8za7TGX8LSwYna0cXthvqUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_Async#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_Async#LambdaHandler.g.verified.cs index d9a37a8b..a688a8ba 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_Async#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_Async#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "K/A2Yp4hzHbk21l61w6haLYAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -66,13 +79,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "K/A2Yp4hzHbk21l61w6haKUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait#LambdaHandler.g.verified.cs index ff4ba7d2..64622794 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "VH5MZQ3KsBJFkPsnivxIPdQAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -66,13 +79,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "VH5MZQ3KsBJFkPsnivxIPcMAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait_EventAndResponseDifferentNamespace#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait_EventAndResponseDifferentNamespace#LambdaHandler.g.verified.cs index 57afef3a..f6621812 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait_EventAndResponseDifferentNamespace#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputDi_AsyncAndAwait_EventAndResponseDifferentNamespace#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(11,8) [InterceptsLocation(1, "2v0Mx0/EAUlNqfkx9U5JLucAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -66,13 +79,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "2v0Mx0/EAUlNqfkx9U5JLtYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputStream#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputStream#LambdaHandler.g.verified.cs index 58542a8e..71622551 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputStream#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_InputStream#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(10,8) [InterceptsLocation(1, "EIytviO7ID8d+8z3oQ4Pu8cAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -60,11 +63,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "EIytviO7ID8d+8z3oQ4Pu7YAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(8,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_NoOutput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_NoOutput#LambdaHandler.g.verified.cs index 3ed5a217..2e7f3425 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_NoOutput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_NoOutput#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "YIbj7XiC2amhwIlyj2HW1bYAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -58,11 +61,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "YIbj7XiC2amhwIlyj2HW1aUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnGenericObject#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnGenericObject#LambdaHandler.g.verified.cs index 58bfca4c..e4ddccae 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnGenericObject#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnGenericObject#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "XdsFhkLY1aZYCRYD2HXHFrUAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create>(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "XdsFhkLY1aZYCRYD2HXHFqQAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnNullablePrimitive#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnNullablePrimitive#LambdaHandler.g.verified.cs index 47ce64d1..b56aa222 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnNullablePrimitive#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnNullablePrimitive#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "fUFDCv62We6/lGMG9FpYS7UAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "fUFDCv62We6/lGMG9FpYS6QAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnString#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnString#LambdaHandler.g.verified.cs index 16f6afa4..1c0443c1 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnString#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NoInput_ReturnString#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "Ta7Dv3cnwIzvY2JBRc5ijLYAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "Ta7Dv3cnwIzvY2JBRc5ijKUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnExplicitNullable#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnExplicitNullable#LambdaHandler.g.verified.cs index 5e10cfbd..3915a303 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnExplicitNullable#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnExplicitNullable#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "xtIY1NRH4poO99GLmpoGnbUAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,13 +80,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "xtIY1NRH4poO99GLmpoGnaQAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnImplicitNullable#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnImplicitNullable#LambdaHandler.g.verified.cs index 65a0c6c3..4291d3bb 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnImplicitNullable#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_NullableInput_ReturnImplicitNullable#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(8,8) [InterceptsLocation(1, "qtXEOV1k02+RkXoOA59GBrUAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -67,13 +80,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "qtXEOV1k02+RkXoOA59GBqQAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(6,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitTask#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitTask#LambdaHandler.g.verified.cs index eb02a62c..742b789b 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitTask#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitTask#LambdaHandler.g.verified.cs @@ -30,38 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "UWCFzECps5Zv/K6OoUlGmtMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { await castHandler.Invoke(); } } - - [InterceptsLocation(1, "UWCFzECps5Zv/K6OoUlGmsIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitType#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitType#LambdaHandler.g.verified.cs index 2d04e72d..16eb612f 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitType#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/ExpressionLambdaVerifyTests.Test_ExpressionLambda_ReturnExplicitType#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "4J9qyNm4aQaoE9yV4I7wUNMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -65,13 +78,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "4J9qyNm4aQaoE9yV4I7wUMIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_FloatingPointTypes#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_FloatingPointTypes#LambdaHandler.g.verified.cs index 234019ae..dbbc06aa 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_FloatingPointTypes#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_FloatingPointTypes#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(12,8) [InterceptsLocation(1, "Zx6wWbKlfl6HcErqMOpfK2EBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -66,11 +69,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "Zx6wWbKlfl6HcErqMOpfK1ABAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(10,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_IntAndLongKeys#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_IntAndLongKeys#LambdaHandler.g.verified.cs index 6b0c43ad..6f7e81db 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_IntAndLongKeys#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_IntAndLongKeys#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(12,8) [InterceptsLocation(1, "XD0eRdQJ2xwEO5+zwdJ8IV0BAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -66,11 +69,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "XD0eRdQJ2xwEO5+zwdJ8IUwBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(10,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_OtherTypes#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_OtherTypes#LambdaHandler.g.verified.cs index a0f23df0..55a711ad 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_OtherTypes#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_OtherTypes#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(14,8) [InterceptsLocation(1, "FPApiCPACeBSE0aOLeXmruQBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -70,11 +73,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "FPApiCPACeBSE0aOLeXmrtMBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(12,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_SmallIntegerTypes#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_SmallIntegerTypes#LambdaHandler.g.verified.cs index 891fa8f5..5ef64501 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_SmallIntegerTypes#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_SmallIntegerTypes#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(13,8) [InterceptsLocation(1, "N8+wyBYUokyoNUAIxBkzoqsBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -68,11 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "N8+wyBYUokyoNUAIxBkzopoBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(11,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_StringAndEnumKeys#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_StringAndEnumKeys#LambdaHandler.g.verified.cs index b5f74e7c..c4c66f24 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_StringAndEnumKeys#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_StringAndEnumKeys#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(13,8) [InterceptsLocation(1, "rMkFDEUYJ34h2/gSzQaFl7YBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -68,11 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "rMkFDEUYJ34h2/gSzQaFl6UBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(11,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_UnsignedIntegerTypes#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_UnsignedIntegerTypes#LambdaHandler.g.verified.cs index 27bd35b1..94940e25 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_UnsignedIntegerTypes#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/KeyedServiceVerifyTests.Test_KeyedService_UnsignedIntegerTypes#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(13,8) [InterceptsLocation(1, "3eiN2asEW2/G+R1Aj4dbcqIBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -68,11 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "3eiN2asEW2/G+R1Aj4dbcpEBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(11,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_AsyncVoid#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_AsyncVoid#LambdaHandler.g.verified.cs index c113ebb9..d680e850 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_AsyncVoid#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_AsyncVoid#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "z6sS8Y9yXWmqDTL/J/JyOsMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -58,11 +61,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "z6sS8Y9yXWmqDTL/J/JyOrIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_Async_ReturnTaskString#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_Async_ReturnTaskString#LambdaHandler.g.verified.cs index d42ac9af..e0ae781e 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_Async_ReturnTaskString#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_Async_ReturnTaskString#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "W6/BEm8FxiRW0gVV9g5fFtMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -62,12 +70,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "W6/BEm8FxiRW0gVV9g5fFsIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_InputDiKeyedServices#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_InputDiKeyedServices#LambdaHandler.g.verified.cs index 2cf0f296..e73ca3cb 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_InputDiKeyedServices#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_InputDiKeyedServices#LambdaHandler.g.verified.cs @@ -30,27 +30,40 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(11,8) [InterceptsLocation(1, "8oeVcVLGeqitmbmG/7HeZwABAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(EventFeatureProviderKey)) + application.Properties[EventFeatureProviderKey] = application + .Services.GetRequiredService() + .Create(); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -73,13 +86,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "8oeVcVLGeqitmbmG/7HeZ+8AAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast#LambdaHandler.g.verified.cs index cce8b5bf..5650dddd 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "I4oSgX2EhCjJlUv+muXhcMMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "I4oSgX2EhCjJlUv+muXhcLIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast_Static#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast_Static#LambdaHandler.g.verified.cs index f8dc0021..7ceff931 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast_Static#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_BlockBody_TypeCast_Static#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "MYd9JR07N7unKiyCLFng0cMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "MYd9JR07N7unKiyCLFng0bIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_NoInput_NoOutput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_NoInput_NoOutput#LambdaHandler.g.verified.cs index 956e1a2c..6280b42d 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_NoInput_NoOutput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_NoInput_NoOutput#LambdaHandler.g.verified.cs @@ -30,27 +30,30 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "FboZTyPPzSjZNNWYolhn08MAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -58,11 +61,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "FboZTyPPzSjZNNWYolhn07IAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTask#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTask#LambdaHandler.g.verified.cs index b752c9b0..7019b5bd 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTask#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTask#LambdaHandler.g.verified.cs @@ -30,38 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "x4hOcx/Mdm3QPU6QMU8PCtMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { await castHandler.Invoke(); } } - - [InterceptsLocation(1, "x4hOcx/Mdm3QPU6QMU8PCsIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTaskString#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTaskString#LambdaHandler.g.verified.cs index 751a00f1..65925787 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTaskString#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_ReturnTaskString#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "rezyXVdhsY66Ems4DFa9p9MAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; async Task InvocationDelegate(ILambdaHostContext context) { @@ -62,12 +70,5 @@ async Task InvocationDelegate(ILambdaHostContext context) responseFeature.SetResponse(response); } } - - [InterceptsLocation(1, "rezyXVdhsY66Ems4DFa9p8IAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_TypeCast_ExtraParentheses#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_TypeCast_ExtraParentheses#LambdaHandler.g.verified.cs index 961e199c..de5c2b88 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_TypeCast_ExtraParentheses#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/MethodHandlerVerifyTests.Test_MethodHandler_TypeCast_ExtraParentheses#LambdaHandler.g.verified.cs @@ -30,27 +30,35 @@ namespace AwsLambda.Host.Core.Generated { using System; using System.CodeDom.Compiler; - using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; - using Amazon.Lambda.Core; using AwsLambda.Host.Builder; using AwsLambda.Host.Core; using Microsoft.Extensions.DependencyInjection; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions + file static class GeneratedLambdaInvocationBuilderExtensions { + private const string EventFeatureProviderKey = "__EventFeatureProvider"; + private const string ResponseFeatureProviderKey = "__ResponseFeatureProvider"; + // Location: InputFile.cs(9,8) [InterceptsLocation(1, "3PhYgT8MPlODZy+E9raU0cMAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( + internal static ILambdaInvocationBuilder MapHandlerInterceptor0( this ILambdaInvocationBuilder application, Delegate handler ) { var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); + + application.Handle(InvocationDelegate); + + if (!application.Properties.ContainsKey(ResponseFeatureProviderKey)) + application.Properties[ResponseFeatureProviderKey] = application. + Services.GetRequiredService() + .Create(); + + return application; Task InvocationDelegate(ILambdaHostContext context) { @@ -63,12 +71,5 @@ Task InvocationDelegate(ILambdaHostContext context) return Task.CompletedTask; } } - - [InterceptsLocation(1, "3PhYgT8MPlODZy+E9raU0bIAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } } } diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_ExplicitReturnTypeAsync#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_ExplicitReturnTypeAsync#LambdaHandler.g.verified.cs index bdda4c75..cb509016 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_ExplicitReturnTypeAsync#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_ExplicitReturnTypeAsync#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "B75vzDHbMAaDhY3yPDqta9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDi#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDi#LambdaHandler.g.verified.cs index 20e3a5b9..fdf3271e 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDi#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDi#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "kxwv6MRO7ICWs0/b3FHQYdQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDiAndReturnUnexpectedType#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDiAndReturnUnexpectedType#LambdaHandler.g.verified.cs index c81a8183..c3be8b7c 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDiAndReturnUnexpectedType#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_AsyncAndDiAndReturnUnexpectedType#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "0/e3oTWVwerLdIUT9JSUddQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_NoDi#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_NoDi#LambdaHandler.g.verified.cs index 67c410a8..4fac26bf 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_NoDi#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MethodHandler_NoDi#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(12,8) [InterceptsLocation(1, "J+znASUyU6XOeL5I7F4a2u4AAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MultipleCalls#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MultipleCalls#LambdaHandler.g.verified.cs index e4527253..ffa8d89c 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MultipleCalls#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_MultipleCalls#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "WS5xwmfdbttlkCDwmVN/4dQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_NoOutput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_NoOutput#LambdaHandler.g.verified.cs index cb450aee..8b714fe9 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_NoOutput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_NoOutput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "DJFXn3qtRzPpemNQ7yH2j9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnAsyncBool#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnAsyncBool#LambdaHandler.g.verified.cs index 2a8d7121..df732b9c 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnAsyncBool#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnAsyncBool#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "/9UlP4Hk4OFxTvOz4lI3ztQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnBool#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnBool#LambdaHandler.g.verified.cs index 2000a21e..b5cb6dba 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnBool#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnBool#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "bfzzWql3BD1qSjdb9bBzM9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedType#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedType#LambdaHandler.g.verified.cs index 72b2ddfe..a77f3065 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedType#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedType#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "4+YRMciUNXwEwXhvIACxZ9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeAsync#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeAsync#LambdaHandler.g.verified.cs index 08f4aca8..e185e626 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeAsync#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeAsync#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "NcMerHwPBzsgxA7y/XPnH9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeTask#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeTask#LambdaHandler.g.verified.cs index 47a52c64..08f2a165 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeTask#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnNotExpectedTypeTask#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "9fSKeCRgj7MIXk9wvEO289QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnTaskBool#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnTaskBool#LambdaHandler.g.verified.cs index 7f927e91..0e082f1b 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnTaskBool#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NoInput_ReturnTaskBool#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "CDEFUo2VYVYEIicqNdjtudQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs index b690191b..622ef238 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "r7SIx1Ceo55ncYApA9O0wtQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs index d146c748..bcc90a41 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(12,8) [InterceptsLocation(1, "mD/AfkPVjS93ZD5vENLVJBwBAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_PrimitiveInput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_PrimitiveInput#LambdaHandler.g.verified.cs index d95d0d13..a8d672a5 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_PrimitiveInput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnInitVerifyTests.Test_OnInit_PrimitiveInput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnInitLambdaApplicationExtensions + file static class GeneratedLambdaOnInitBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "4H720O/JvOGs29mmtmYgitQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_BlockLambda_ReturnsImplicitVoid#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_BlockLambda_ReturnsImplicitVoid#LambdaHandler.g.verified.cs index bd7cff11..8cdb556b 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_BlockLambda_ReturnsImplicitVoid#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_BlockLambda_ReturnsImplicitVoid#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "JG45SVupAX32PicMEg4KYMQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_MultipleCalls#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_MultipleCalls#LambdaHandler.g.verified.cs index 47408a48..a21a7379 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_MultipleCalls#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_MultipleCalls#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "8z0FL9iGVp57G+1Z1fBD39QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput#LambdaHandler.g.verified.cs index 009490ea..2cbcf78a 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "qjTMZJmT/ICwyqjvKYAro9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedType#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedType#LambdaHandler.g.verified.cs index cffadb35..b7be06a8 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedType#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedType#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "xOmLseZGX64ZVN3IS0hGL9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeAsync#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeAsync#LambdaHandler.g.verified.cs index f9d45256..e8c28781 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeAsync#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeAsync#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "nxe3yEiiRmdYDNQcN1k3hdQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeTask#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeTask#LambdaHandler.g.verified.cs index a31edeaa..5d5d7841 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeTask#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NoInput_ReturnUnexpectedTypeTask#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "2tTPAN/rsaZuzGty9hzBK9QAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs index 19e01b05..bf74bdaf 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_NullableValueAndReferenceInputs#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "UPiaK81+RguBpV3LlTD6qtQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs index 74d24674..6dc057d1 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_OneOfEachPossibleKindOfInput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(12,8) [InterceptsLocation(1, "YiehluDLQPPtk+Ko8lbJChwBAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_PrimitiveInput#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_PrimitiveInput#LambdaHandler.g.verified.cs index f61b14b1..d888bebc 100644 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_PrimitiveInput#LambdaHandler.g.verified.cs +++ b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OnShutdownVerifyTests.Test_OnShutdown_PrimitiveInput#LambdaHandler.g.verified.cs @@ -35,10 +35,9 @@ namespace AwsLambda.Host.Core.Generated using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OnShutdownLambdaApplicationExtensions + file static class GeneratedLambdaOnShutdownBuilderExtensions { // Location: InputFile.cs(10,8) [InterceptsLocation(1, "QR3PHAM1SBBcUgDZGFYhBtQAAABJbnB1dEZpbGUuY3M=")] diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_EventAndResponse#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_EventAndResponse#LambdaHandler.g.verified.cs deleted file mode 100644 index 75495a3a..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_EventAndResponse#LambdaHandler.g.verified.cs +++ /dev/null @@ -1,98 +0,0 @@ -//HintName: LambdaHandler.g.cs -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -#nullable enable - -namespace System.Runtime.CompilerServices -{ - using System.CodeDom.Compiler; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - file sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(int version, string data) - { - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System; - using System.CodeDom.Compiler; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Amazon.Lambda.Core; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - using Microsoft.Extensions.DependencyInjection; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions - { - // Location: InputFile.cs(11,8) - [InterceptsLocation(1, "QmALRs8r2abUfl00isjWKtkAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( - this ILambdaInvocationBuilder application, - Delegate handler - ) - { - var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); - - Task InvocationDelegate(ILambdaHostContext context) - { - // ParameterInfo { Type = global::Request, Name = request, Source = Event, IsNullable = False, IsOptional = False} - var arg0 = context.GetRequiredEvent(); - var response = castHandler.Invoke(arg0); - if (context.Features.Get() is not IResponseFeature responseFeature) - { - throw new InvalidOperationException($"Response feature for type 'global::Response' is not available in the collection."); - } - responseFeature.SetResponse(response); - return Task.CompletedTask; - } - } - - [InterceptsLocation(1, "QmALRs8r2abUfl00isjWKqUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OpenTelemetryLambdaApplicationExtensions - { - [InterceptsLocation(1, "QmALRs8r2abUfl00isjWKrYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,8) - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - return application.Use(application.Services.GetOpenTelemetryTracer()); - } - } -} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_ExpressionLambda_DiAndAsyncAndAwait#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_ExpressionLambda_DiAndAsyncAndAwait#LambdaHandler.g.verified.cs deleted file mode 100644 index 9aa63f7e..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_ExpressionLambda_DiAndAsyncAndAwait#LambdaHandler.g.verified.cs +++ /dev/null @@ -1,99 +0,0 @@ -//HintName: LambdaHandler.g.cs -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -#nullable enable - -namespace System.Runtime.CompilerServices -{ - using System.CodeDom.Compiler; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - file sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(int version, string data) - { - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System; - using System.CodeDom.Compiler; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Amazon.Lambda.Core; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - using Microsoft.Extensions.DependencyInjection; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions - { - // Location: InputFile.cs(13,8) - [InterceptsLocation(1, "mX/YeIwGYTTDQe0umNPm4ScBAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( - this ILambdaInvocationBuilder application, - Delegate handler - ) - { - var castHandler = (global::System.Func>)handler; - - return application.Handle(InvocationDelegate); - - async Task InvocationDelegate(ILambdaHostContext context) - { - // ParameterInfo { Type = string, Name = input, Source = Event, IsNullable = False, IsOptional = False} - var arg0 = context.GetRequiredEvent(); - // ParameterInfo { Type = global::IService, Name = service, Source = Service, IsNullable = False, IsOptional = False} - var arg1 = context.ServiceProvider.GetRequiredService(); - var response = await castHandler.Invoke(arg0, arg1); - if (context.Features.Get() is not IResponseFeature responseFeature) - { - throw new InvalidOperationException($"Response feature for type 'string' is not available in the collection."); - } - responseFeature.SetResponse(response); - } - } - - [InterceptsLocation(1, "mX/YeIwGYTTDQe0umNPm4fMAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - builder.Services.AddSingleton>(); - return builder.Build(); - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OpenTelemetryLambdaApplicationExtensions - { - [InterceptsLocation(1, "mX/YeIwGYTTDQe0umNPm4QQBAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(11,8) - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - return application.Use(application.Services.GetOpenTelemetryTracer()); - } - } -} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_NoEventNoResponse#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_NoEventNoResponse#LambdaHandler.g.verified.cs deleted file mode 100644 index 42c9fa5b..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_NoEventNoResponse#LambdaHandler.g.verified.cs +++ /dev/null @@ -1,89 +0,0 @@ -//HintName: LambdaHandler.g.cs -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -#nullable enable - -namespace System.Runtime.CompilerServices -{ - using System.CodeDom.Compiler; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - file sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(int version, string data) - { - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System; - using System.CodeDom.Compiler; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Amazon.Lambda.Core; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - using Microsoft.Extensions.DependencyInjection; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions - { - // Location: InputFile.cs(11,8) - [InterceptsLocation(1, "PVdPB+yDglPnV0ZNm2bBKtkAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( - this ILambdaInvocationBuilder application, - Delegate handler - ) - { - var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); - - Task InvocationDelegate(ILambdaHostContext context) - { - castHandler.Invoke(); - return Task.CompletedTask; - } - } - - [InterceptsLocation(1, "PVdPB+yDglPnV0ZNm2bBKqUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - return builder.Build(); - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OpenTelemetryLambdaApplicationExtensions - { - [InterceptsLocation(1, "PVdPB+yDglPnV0ZNm2bBKrYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,8) - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - return application.Use(application.Services.GetOpenTelemetryTracerNoEventNoResponse()); - } - } -} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyEvent#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyEvent#LambdaHandler.g.verified.cs deleted file mode 100644 index e83b4c78..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyEvent#LambdaHandler.g.verified.cs +++ /dev/null @@ -1,92 +0,0 @@ -//HintName: LambdaHandler.g.cs -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -#nullable enable - -namespace System.Runtime.CompilerServices -{ - using System.CodeDom.Compiler; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - file sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(int version, string data) - { - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System; - using System.CodeDom.Compiler; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Amazon.Lambda.Core; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - using Microsoft.Extensions.DependencyInjection; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions - { - // Location: InputFile.cs(11,8) - [InterceptsLocation(1, "3DxEwWle1IoQD99wxHvHPdkAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( - this ILambdaInvocationBuilder application, - Delegate handler - ) - { - var castHandler = (global::System.Action)handler; - - return application.Handle(InvocationDelegate); - - Task InvocationDelegate(ILambdaHostContext context) - { - // ParameterInfo { Type = global::Request, Name = request, Source = Event, IsNullable = False, IsOptional = False} - var arg0 = context.GetRequiredEvent(); - castHandler.Invoke(arg0); - return Task.CompletedTask; - } - } - - [InterceptsLocation(1, "3DxEwWle1IoQD99wxHvHPaUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OpenTelemetryLambdaApplicationExtensions - { - [InterceptsLocation(1, "3DxEwWle1IoQD99wxHvHPbYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,8) - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - return application.Use(application.Services.GetOpenTelemetryTracerNoResponse()); - } - } -} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyResponse#LambdaHandler.g.verified.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyResponse#LambdaHandler.g.verified.cs deleted file mode 100644 index b6405d45..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/Snapshots/OtelEnabledVerifyTests.Test_OtelEnabled_OnlyResponse#LambdaHandler.g.verified.cs +++ /dev/null @@ -1,95 +0,0 @@ -//HintName: LambdaHandler.g.cs -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -#nullable enable - -namespace System.Runtime.CompilerServices -{ - using System.CodeDom.Compiler; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - file sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(int version, string data) - { - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System; - using System.CodeDom.Compiler; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Amazon.Lambda.Core; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - using Microsoft.Extensions.DependencyInjection; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class MapHandlerLambdaApplicationExtensions - { - // Location: InputFile.cs(11,8) - [InterceptsLocation(1, "V1rdx21g5a+slUYwHpqULNkAAABJbnB1dEZpbGUuY3M=")] - internal static ILambdaInvocationBuilder MapHandlerInterceptor( - this ILambdaInvocationBuilder application, - Delegate handler - ) - { - var castHandler = (global::System.Func)handler; - - return application.Handle(InvocationDelegate); - - Task InvocationDelegate(ILambdaHostContext context) - { - var response = castHandler.Invoke(); - if (context.Features.Get() is not IResponseFeature responseFeature) - { - throw new InvalidOperationException($"Response feature for type 'global::Response' is not available in the collection."); - } - responseFeature.SetResponse(response); - return Task.CompletedTask; - } - } - - [InterceptsLocation(1, "V1rdx21g5a+slUYwHpqULKUAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(7,22) - internal static LambdaApplication BuildInterceptor(this LambdaApplicationBuilder builder) - { - builder.Services.AddSingleton>(); - return builder.Build(); - } - } -} - -namespace AwsLambda.Host.Core.Generated -{ - using System.CodeDom.Compiler; - using System.Runtime.CompilerServices; - using Microsoft.Extensions.DependencyInjection; - using AwsLambda.Host.Builder; - using AwsLambda.Host.Core; - - [GeneratedCode("AwsLambda.Host.SourceGenerators", "0.0.0")] - file static class OpenTelemetryLambdaApplicationExtensions - { - [InterceptsLocation(1, "V1rdx21g5a+slUYwHpqULLYAAABJbnB1dEZpbGUuY3M=")] // Location: InputFile.cs(9,8) - internal static ILambdaInvocationBuilder UseOpenTelemetryTracingInterceptor( - this ILambdaInvocationBuilder application - ) - { - return application.Use(application.Services.GetOpenTelemetryTracerNoEvent()); - } - } -} diff --git a/tests/AwsLambda.Host.SourceGenerators.UnitTests/VerifyTests/OtelEnabledVerifyTests.cs b/tests/AwsLambda.Host.SourceGenerators.UnitTests/VerifyTests/OtelEnabledVerifyTests.cs deleted file mode 100644 index e1d79b26..00000000 --- a/tests/AwsLambda.Host.SourceGenerators.UnitTests/VerifyTests/OtelEnabledVerifyTests.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace AwsLambda.Host.SourceGenerators.UnitTests; - -public class OtelEnabledVerifyTests -{ - [Fact] - public async Task Test_OtelEnabled_EventAndResponse() => - await GeneratorTestHelpers.Verify( - """ - using AwsLambda.Host.Core; - using AwsLambda.Host.Builder; - using Microsoft.Extensions.Hosting; - - var builder = LambdaApplication.CreateBuilder(); - - var lambda = builder.Build(); - - lambda.UseOpenTelemetryTracing(); - - lambda.MapHandler(([Event] Request request) => new Response($"Hello {request.Name}!")); - - await lambda.RunAsync(); - - record Request(string Name); - - record Response(string Message); - """ - ); - - [Fact] - public async Task Test_OtelEnabled_OnlyResponse() => - await GeneratorTestHelpers.Verify( - """ - using AwsLambda.Host.Core; - using AwsLambda.Host.Builder; - using Microsoft.Extensions.Hosting; - - var builder = LambdaApplication.CreateBuilder(); - - var lambda = builder.Build(); - - lambda.UseOpenTelemetryTracing(); - - lambda.MapHandler(() => new Response("Hello world!")); - - await lambda.RunAsync(); - - record Response(string Message); - """ - ); - - [Fact] - public async Task Test_OtelEnabled_OnlyEvent() => - await GeneratorTestHelpers.Verify( - """ - using AwsLambda.Host.Core; - using AwsLambda.Host.Builder; - using Microsoft.Extensions.Hosting; - - var builder = LambdaApplication.CreateBuilder(); - - var lambda = builder.Build(); - - lambda.UseOpenTelemetryTracing(); - - lambda.MapHandler(([Event] Request request) => { }); - - await lambda.RunAsync(); - - record Request(string Name); - """ - ); - - [Fact] - public async Task Test_OtelEnabled_NoEventNoResponse() => - await GeneratorTestHelpers.Verify( - """ - using AwsLambda.Host.Core; - using AwsLambda.Host.Builder; - using Microsoft.Extensions.Hosting; - - var builder = LambdaApplication.CreateBuilder(); - - var lambda = builder.Build(); - - lambda.UseOpenTelemetryTracing(); - - lambda.MapHandler(() => { }); - - await lambda.RunAsync(); - """ - ); - - [Fact] - public async Task Test_OtelEnabled_ExpressionLambda_DiAndAsyncAndAwait() => - await GeneratorTestHelpers.Verify( - """ - using System.Threading.Tasks; - using AwsLambda.Host.Core; - using AwsLambda.Host.Builder; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.Hosting; - - var builder = LambdaApplication.CreateBuilder(); - - var lambda = builder.Build(); - - lambda.UseOpenTelemetryTracing(); - - lambda.MapHandler( - async ([Event] string input, IService service) => (await service.GetMessage()).ToUpper() - ); - - await lambda.RunAsync(); - - public interface IService - { - Task GetMessage(); - } - """ - ); -} diff --git a/tests/AwsLambda.Host.UnitTests/Builder/Extensions/ServiceCollectionExtensionsTests.cs b/tests/AwsLambda.Host.UnitTests/Builder/Extensions/ServiceCollectionExtensionsTests.cs index 9991bfbb..61d09d91 100644 --- a/tests/AwsLambda.Host.UnitTests/Builder/Extensions/ServiceCollectionExtensionsTests.cs +++ b/tests/AwsLambda.Host.UnitTests/Builder/Extensions/ServiceCollectionExtensionsTests.cs @@ -31,7 +31,7 @@ public void AddLambdaHostCoreServices_WithValidServiceCollection_ReturnsServiceC } [Theory] - [InlineData(11)] + [InlineData(13)] public void AddLambdaHostCoreServices_RegistersExactlyNServices(int servicesCount) { // Arrange diff --git a/tests/AwsLambda.Host.UnitTests/Core/Context/LambdaHostContextFactoryTests.cs b/tests/AwsLambda.Host.UnitTests/Core/Context/LambdaHostContextFactoryTests.cs index a41ce173..009bb927 100644 --- a/tests/AwsLambda.Host.UnitTests/Core/Context/LambdaHostContextFactoryTests.cs +++ b/tests/AwsLambda.Host.UnitTests/Core/Context/LambdaHostContextFactoryTests.cs @@ -70,7 +70,7 @@ internal void Create_CallsFeatureCollectionFactoryCreate( _ = factory.Create(lambdaContext, properties, CancellationToken.None); // Assert - featureCollectionFactory.Received(1).Create(); + featureCollectionFactory.Received(1).Create(Arg.Any>()); } [Theory] @@ -96,4 +96,36 @@ internal void Create_WithContextAccessor_SetsContextOnAccessor( // Assert contextAccessor!.LambdaHostContext.Should().NotBeNull(); } + + [Theory] + [AutoNSubstituteData] + internal void Create_GetsFeaturesFromProperties( + [Frozen] IFeatureCollectionFactory featureCollectionFactory, + IFeatureProvider eventFeatureProvider, + IFeatureProvider responseFeatureProvider, + ILambdaHostContext lambdaContext, + LambdaHostContextFactory factory + ) + { + // Arrange + var properties = new Dictionary + { + [LambdaInvocationBuilder.EventFeatureProviderKey] = eventFeatureProvider, + [LambdaInvocationBuilder.ResponseFeatureProviderKey] = responseFeatureProvider, + }; + + // Act + _ = factory.Create(lambdaContext, properties, CancellationToken.None); + + // Assert + featureCollectionFactory + .Received(1) + .Create( + Arg.Is>(providers => + providers.Count() == 2 + && providers.Contains(eventFeatureProvider) + && providers.Contains(responseFeatureProvider) + ) + ); + } } diff --git a/tests/AwsLambda.Host.UnitTests/Core/Features/DefaultFeatureCollectionFactoryTests.cs b/tests/AwsLambda.Host.UnitTests/Core/Features/DefaultFeatureCollectionFactoryTests.cs index d11d3873..496eaabc 100644 --- a/tests/AwsLambda.Host.UnitTests/Core/Features/DefaultFeatureCollectionFactoryTests.cs +++ b/tests/AwsLambda.Host.UnitTests/Core/Features/DefaultFeatureCollectionFactoryTests.cs @@ -3,35 +3,38 @@ namespace AwsLambda.Host.UnitTests.Core.Features; [TestSubject(typeof(DefaultFeatureCollectionFactory))] public class DefaultFeatureCollectionFactoryTest { - [Fact] - public void Create_ReturnsIFeatureCollection() + [Theory] + [AutoNSubstituteData] + public void Create_ReturnsIFeatureCollection(IEnumerable featureProviders) { // Arrange var factory = new DefaultFeatureCollectionFactory([]); // Act - var collection = factory.Create(); + var collection = factory.Create(featureProviders); // Assert collection.Should().BeAssignableTo(); } - [Fact] - public void Create_ReturnsNewInstanceEachCall() + [Theory] + [AutoNSubstituteData] + public void Create_ReturnsNewInstanceEachCall(IEnumerable featureProviders) { // Arrange var factory = new DefaultFeatureCollectionFactory([]); // Act - var collection1 = factory.Create(); - var collection2 = factory.Create(); + var collection1 = factory.Create(featureProviders); + var collection2 = factory.Create(featureProviders); // Assert collection1.Should().NotBeSameAs(collection2); } - [Fact] - public void Create_PassesProvidersToCollection() + [Theory] + [AutoNSubstituteData] + public void Create_PassesProvidersToCollection(IEnumerable featureProviders) { // Arrange var provider = Substitute.For(); @@ -46,7 +49,7 @@ public void Create_PassesProvidersToCollection() }); // Act - var collection = factory.Create(); + var collection = factory.Create(featureProviders); var result = collection.Get(); // Assert diff --git a/tests/AwsLambda.Host.UnitTests/Core/Features/EventFeatureProviderFactoryTest.cs b/tests/AwsLambda.Host.UnitTests/Core/Features/EventFeatureProviderFactoryTest.cs new file mode 100644 index 00000000..8ddd3b6e --- /dev/null +++ b/tests/AwsLambda.Host.UnitTests/Core/Features/EventFeatureProviderFactoryTest.cs @@ -0,0 +1,27 @@ +namespace AwsLambda.Host.UnitTests.Core.Features; + +[TestSubject(typeof(EventFeatureProviderFactory))] +public class EventFeatureProviderFactoryTest +{ + [Theory] + [AutoNSubstituteData] + internal void Create_ReturnsDefaultEventFeatureProvider(EventFeatureProviderFactory sut) + { + // Act + var provider = sut.Create(); + + // Assert + provider.Should().BeOfType>(); + } + + [Theory] + [AutoNSubstituteData] + internal void Create_ReturnsIFeatureProvider(EventFeatureProviderFactory sut) + { + // Act + var provider = sut.Create(); + + // Assert + provider.Should().BeAssignableTo(); + } +} diff --git a/tests/AwsLambda.Host.UnitTests/Core/Features/ResponseFeatureProviderFactoryTest.cs b/tests/AwsLambda.Host.UnitTests/Core/Features/ResponseFeatureProviderFactoryTest.cs new file mode 100644 index 00000000..ee375d57 --- /dev/null +++ b/tests/AwsLambda.Host.UnitTests/Core/Features/ResponseFeatureProviderFactoryTest.cs @@ -0,0 +1,27 @@ +namespace AwsLambda.Host.UnitTests.Core.Features; + +[TestSubject(typeof(ResponseFeatureProviderFactory))] +public class ResponseFeatureProviderFactoryTest +{ + [Theory] + [AutoNSubstituteData] + internal void Create_ReturnsDefaultEventFeatureProvider(ResponseFeatureProviderFactory sut) + { + // Act + var provider = sut.Create(); + + // Assert + provider.Should().BeOfType>(); + } + + [Theory] + [AutoNSubstituteData] + internal void Create_ReturnsIFeatureProvider(ResponseFeatureProviderFactory sut) + { + // Act + var provider = sut.Create(); + + // Assert + provider.Should().BeAssignableTo(); + } +}