Skip to content

Commit 45c89ba

Browse files
committed
Adds More Convenient Typed Startup for ASP.NET Core
1 parent 039726b commit 45c89ba

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace Amazon.Lambda.AspNetCoreServer
2323
{
2424
/// <summary>
25-
/// ApiGatewayFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
25+
/// ApiGatewayProxyFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
2626
/// the Init method similar to Main function in the ASP.NET Core. The function handler for the Lambda function will point
2727
/// to this base class FunctionHandlerAsync method.
2828
/// </summary>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
3+
namespace Amazon.Lambda.AspNetCoreServer
4+
{
5+
/// <summary>
6+
/// ApiGatewayProxyFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
7+
/// the Init method similar to Main function in the ASP.NET Core and provides typed Startup. The function handler for
8+
/// the Lambda function will point to this base class FunctionHandlerAsync method.
9+
/// </summary>
10+
/// <typeparam name ="TStartup">The type containing the startup methods for the application.</typeparam>
11+
public abstract class APIGatewayProxyFunction<TStartup> : APIGatewayProxyFunction where TStartup : class
12+
{
13+
/// <inheritdoc/>
14+
protected override IWebHostBuilder CreateWebHostBuilder() =>
15+
base.CreateWebHostBuilder().UseStartup<TStartup>();
16+
}
17+
}

Libraries/test/TestWebApp/LambdaFunction.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55

66
namespace TestWebApp
77
{
8-
public class LambdaFunction : APIGatewayProxyFunction
8+
public class LambdaFunction : APIGatewayProxyFunction<Startup>
99
{
1010
public const string BinaryContentType = "application/octet-stream";
1111

1212
protected override void Init(IWebHostBuilder builder)
1313
{
1414
builder
1515
.UseApiGateway()
16-
.UseContentRoot(Directory.GetCurrentDirectory())
17-
.UseStartup<Startup>();
16+
.UseContentRoot(Directory.GetCurrentDirectory());
1817
}
1918
}
2019
}

0 commit comments

Comments
 (0)