Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active December 26, 2021 00:27
Show Gist options
  • Save davidfowl/1fdbc02ef9511e2729a914a8c9f3ab27 to your computer and use it in GitHub Desktop.
Save davidfowl/1fdbc02ef9511e2729a914a8c9f3ab27 to your computer and use it in GitHub Desktop.
A minimal fully asynchronous C# ASP.NET Core 3.0 application with routing (learn more about ASP.NET Core here https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-3.0)
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(route =>
{
route.MapGet("/", context => context.Response.WriteAsync("Hello world"));
});
});
})
.Build().Run();
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
</Project>
@pimbrouwers
Copy link

@davidfowl Love this! Such an emphasis on bare bones these days, and I feel as though .NET is sometimes still viewed as cumbersome. Which I don't believe is the case at all.

Created a version without the default host builder, to make things a bit more explicit for potential newcomers. Seeing this as a potential acorn for new projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment