Skip to content

Instantly share code, notes, and snippets.

View talkingdotnet's full-sized avatar

Talking Dotnet talkingdotnet

View GitHub Profile
var builder = WebApplication.CreateBuilder(args)
.RegisterServices();
var app = builder.Build()
.SetupMiddleware();
app.Run();
WebApplication.CreateBuilder(args)
.RegisterServices()
.Build()
.SetupMiddleware()
.Run();
public static class RegisterStartupMiddlewares
{
public static WebApplication SetupMiddleware(this WebApplication app)
{
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
public static class RegisterStartupServices
{
public static WebApplicationBuilder RegisterServices(this WebApplicationBuilder builder)
{
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
return builder;
}
var startup = new Startup(builder.Configuration);
startup.RegisterServices(builder.Services);
var app = builder.Build();
startup.SetupMiddlewares(app, builder.Environment);
var builder = WebApplication.CreateBuilder(args);
var startup = new Startup(builder.Configuration);
startup.ConfigureServices(builder.Services);
var app = builder.Build();
startup.Configure(app, builder.Environment);
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();