ASP.NET Core 1 ~ 5 では UseStartup<T>
を使うのが一般的でしたが、使わなくても同等の内容は書けるので、今回は使いませんでした。
また、IConfguration
やロギングやその他のサービスは敢えて省いています。
ASP.NET Core 5 は ASP.NET Core 3 と同じです。
ASP.NET Core 7 および 8 は ASP.NET Core 6 と同じです。
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
new WebHostBuilder() | |
.ConfigureServices(static services => | |
{ | |
}) | |
.Configure(static app => | |
{ | |
app.Use(static _ => static context => context.Response.WriteAsync("Hello, ASP.NET Core 1")); | |
}) | |
.UseKestrel() | |
.UseUrls("http://localhost:5001") | |
.Build() | |
.Run(); |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
WebHost | |
.CreateDefaultBuilder() | |
.ConfigureServices(static services => | |
{ | |
}) | |
.Configure(static app => | |
{ | |
app.Use(static _ => context => context.Response.WriteAsync("Hello, ASP.NET Core 2")); | |
}) | |
.UseUrls("http://localhost:5002") | |
.Build() | |
.Run(); |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Hosting; | |
Host | |
.CreateDefaultBuilder() | |
.ConfigureWebHostDefaults(static webHostBuilder => webHostBuilder | |
.ConfigureServices(static services => | |
{ | |
}) | |
.Configure(static app => | |
{ | |
app.Use(static _ => static context => context.Response.WriteAsync("Hello, ASP.NET Core 3")); | |
}) | |
.UseUrls("http://localhost:5003")) | |
.Build() | |
.Run(); |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
var builder = WebApplication.CreateBuilder(); | |
// builder.Services.AddXxx(); | |
var app = builder.Build(); | |
app.Use(static _ => static context => context.Response.WriteAsync("Hello, ASP.NET Core 6")); | |
app.Run("http://localhost:5006"); |