Skip to content

Adds More Convenient Typed Startup for ASP.NET Core #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace Amazon.Lambda.AspNetCoreServer
{
/// <summary>
/// ApiGatewayFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
/// ApiGatewayProxyFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
/// the Init method similar to Main function in the ASP.NET Core. The function handler for the Lambda function will point
/// to this base class FunctionHandlerAsync method.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Hosting;

namespace Amazon.Lambda.AspNetCoreServer
{
/// <summary>
/// ApiGatewayProxyFunction is the base class that is implemented in a ASP.NET Core Web API. The derived class implements
/// the Init method similar to Main function in the ASP.NET Core and provides typed Startup. The function handler for
/// the Lambda function will point to this base class FunctionHandlerAsync method.
/// </summary>
/// <typeparam name ="TStartup">The type containing the startup methods for the application.</typeparam>
public abstract class APIGatewayProxyFunction<TStartup> : APIGatewayProxyFunction where TStartup : class
{
/// <inheritdoc/>
protected override IWebHostBuilder CreateWebHostBuilder() =>
base.CreateWebHostBuilder().UseStartup<TStartup>();

/// <inheritdoc/>
protected override void Init(IWebHostBuilder builder)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.IO;
using Microsoft.AspNetCore.Mvc;
using static System.Net.Mime.MediaTypeNames;

namespace TestWebApp.Controllers
{
Expand All @@ -14,7 +14,7 @@ public IActionResult Get([FromQuery] string firstName, [FromQuery] string lastNa
for (int i = 0; i < bytes.Length; i++)
bytes[i] = (byte)i;

return base.File(bytes, LambdaFunction.BinaryContentType);
return base.File(bytes, Application.Octet);
}
}
}
}
16 changes: 2 additions & 14 deletions Libraries/test/TestWebApp/LambdaFunction.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
using System.IO;

using Amazon.Lambda.AspNetCoreServer;
using Microsoft.AspNetCore.Hosting;
using Amazon.Lambda.AspNetCoreServer;

namespace TestWebApp
{
public class LambdaFunction : APIGatewayProxyFunction
public class LambdaFunction : APIGatewayProxyFunction<Startup>
{
public const string BinaryContentType = "application/octet-stream";

protected override void Init(IWebHostBuilder builder)
{
builder
.UseApiGateway()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>();
}
}
}