<#@ template language="C#" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Models" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Extensions" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes" #> <#@ import namespace="Microsoft.CodeAnalysis" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Validation" #> <# foreach (var ns in _model.GeneratedMethod.Usings) { #> using <#= ns #>; <# } #> namespace <#= _model.LambdaMethod.ContainingNamespace #> { public class <#= _model.GeneratedMethod.ContainingType.Name #> { <# this.Write(new FieldsAndConstructor(_model).TransformText()); #> public <#= _model.LambdaMethod.ReturnsVoidOrGenericTask ? "async " : "" #><#= _model.GeneratedMethod.ReturnType.FullName #> <#= _model.LambdaMethod.Name #>(<#= string.Join(", ", _model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName} {p.Name}")) #>) { <# if (_model.LambdaMethod.UsingDependencyInjection) { #> // Create a scope for every request, // this allows creating scoped dependencies without creating a scope manually. using var scope = serviceProvider.CreateScope(); var <#= _model.LambdaMethod.ContainingType.Name.ToCamelCase() #> = scope.ServiceProvider.GetRequiredService<<#= _model.LambdaMethod.ContainingType.Name #>>(); <# } if (_model.LambdaMethod.Events.Contains(EventType.API)) { var apiParameters = new APIGatewaySetupParameters(_model); this.Write(apiParameters.TransformText()); this.Write(new APIGatewayInvoke(_model, apiParameters.ParameterSignature).TransformText()); } else if (_model.LambdaMethod.Events.Count == 0) { this.Write(new NoEventMethodBody(_model).TransformText()); } #> } private static void SetExecutionEnvironment() { const string envName = "AWS_EXECUTION_ENV"; var envValue = new StringBuilder(); // If there is an existing execution environment variable add the annotations package as a suffix. if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName))) { envValue.Append($"{Environment.GetEnvironmentVariable(envName)}_"); } envValue.Append("amazon-lambda-annotations_<#= _model.SourceGeneratorVersion #>"); Environment.SetEnvironmentVariable(envName, envValue.ToString()); } } }