Skip to content

Commit

Permalink
Update lambda annotations to eagerly build Function Handler type
Browse files Browse the repository at this point in the history
  • Loading branch information
ppittle authored Nov 12, 2024
1 parent eec92d1 commit 9349e6b
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 18 deletions.
11 changes: 11 additions & 0 deletions .autover/changes/c4272e98-0b59-409c-a060-d5c061495801.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.Annotations",
"Type": "Minor",
"ChangelogMessages": [
"Eagerly build Function Handler inside the Generated class\u0027s constructor"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates
/// Class to produce the template output
/// </summary>

#line 1 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 1 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
public partial class FieldsAndConstructor : FieldsAndConstructorBase
{
Expand All @@ -30,7 +30,7 @@ public partial class FieldsAndConstructor : FieldsAndConstructorBase
public virtual string TransformText()
{

#line 7 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 7 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

if (_model.LambdaMethod.UsingDependencyInjection)
{
Expand All @@ -40,7 +40,7 @@ public virtual string TransformText()
#line hidden
this.Write(" private readonly ServiceProvider serviceProvider;\r\n");

#line 12 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 12 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

}
else
Expand All @@ -51,28 +51,28 @@ public virtual string TransformText()
#line hidden
this.Write(" private readonly ");

#line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 17 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name));

#line default
#line hidden
this.Write(" ");

#line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 17 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase()));

#line default
#line hidden
this.Write(";\r\n private readonly ");

#line 18 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 18 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName));

#line default
#line hidden
this.Write(" serializer;\r\n");

#line 19 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 19 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

}

Expand All @@ -87,14 +87,14 @@ public virtual string TransformText()
/// </summary>
public ");

#line 28 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 28 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.GeneratedMethod.ContainingType.Name));

#line default
#line hidden
this.Write("()\r\n {\r\n SetExecutionEnvironment();\r\n");

#line 31 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 31 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

if (_model.LambdaMethod.UsingDependencyInjection)
{
Expand All @@ -108,29 +108,45 @@ public virtual string TransformText()
// To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method.
services.AddSingleton<");

#line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 39 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name));

#line default
#line hidden
this.Write(">();\r\n services.AddSingleton<");

#line 40 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 40 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName));

#line default
#line hidden
this.Write(">();\r\n\r\n var startup = new ");

#line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 42 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.StartupType.FullName));

#line default
#line hidden
this.Write("();\r\n startup.ConfigureServices(services);\r\n serviceProvide" +
"r = services.BuildServiceProvider();\r\n");
"r = services.BuildServiceProvider();\r\n\r\n // Intentionally eagerly bui" +
"ld ");

#line 45 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 46 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name));

#line default
#line hidden
this.Write(" and its dependencies.\r\n // This causes time spent in the Constructor " +
"to appear on INIT_REPORTs\r\n _ = serviceProvider.GetRequiredService<");

#line 48 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name));

#line default
#line hidden
this.Write(">();\r\n");

#line 49 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

}
else
Expand All @@ -141,28 +157,28 @@ public virtual string TransformText()
#line hidden
this.Write(" ");

#line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 54 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase()));

#line default
#line hidden
this.Write(" = new ");

#line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 54 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name));

#line default
#line hidden
this.Write("();\r\n serializer = new ");

#line 51 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 55 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName));

#line default
#line hidden
this.Write("();\r\n");

#line 52 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"
#line 56 "C:\projects\aws\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
var startup = new <#= _model.StartupType.FullName #>();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build <#= _model.LambdaMethod.ContainingType.Name #> and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<<#= _model.LambdaMethod.ContainingType.Name #>>();
<#
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public FunctionsZipOutput_ToLower_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build FunctionsZipOutput and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<FunctionsZipOutput>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Functions_ToUpper_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build Functions and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<Functions>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Greeter_SayHelloAsync_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build Greeter and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<Greeter>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Greeter_SayHello_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build Greeter and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<Greeter>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Add_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_DivideAsync_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Multiply_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Pi_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Random_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Randoms_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public SimpleCalculator_Subtract_Generated()
var startup = new TestServerlessApp.Startup();
startup.ConfigureServices(services);
serviceProvider = services.BuildServiceProvider();

// Intentionally eagerly build SimpleCalculator and its dependencies.
// This causes time spent in the Constructor to appear on INIT_REPORTs
_ = serviceProvider.GetRequiredService<SimpleCalculator>();
}

/// <summary>
Expand Down

0 comments on commit 9349e6b

Please sign in to comment.