From 34f7d446b278915e4527d5f95dd7cc0b999c37fa Mon Sep 17 00:00:00 2001 From: "Artyom M." Date: Fri, 15 Nov 2024 19:56:36 +0200 Subject: [PATCH] Abandon Startup.cs (#159) --- src/TryMudBlazor.Server/Program.cs | 46 ++++++++++++++++++---- src/TryMudBlazor.Server/Startup.cs | 63 ------------------------------ 2 files changed, 39 insertions(+), 70 deletions(-) delete mode 100644 src/TryMudBlazor.Server/Startup.cs diff --git a/src/TryMudBlazor.Server/Program.cs b/src/TryMudBlazor.Server/Program.cs index 2bbd93d6..cd262b29 100644 --- a/src/TryMudBlazor.Server/Program.cs +++ b/src/TryMudBlazor.Server/Program.cs @@ -1,16 +1,48 @@ +using MudBlazor.Examples.Data; + namespace TryMudBlazor.Server; public class Program { public static void Main(string[] args) { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => + var builder = WebApplication.CreateBuilder(args); + builder.Services.AddScoped(); + builder.Services.AddCors(options => + { + options.AddDefaultPolicy(policy => { - webBuilder.UseStartup(); + policy.WithOrigins("https://www.mudblazor.com", "https://mudblazor.com"); }); + }); + builder.Services.AddControllers(); + + var app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseWebAssemblyDebugging(); + } + else + { + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseCors(); + + // Needed for wasm project + app.UseBlazorFrameworkFiles(); + app.UseStaticFiles(); + + app.MapControllers(); + app.MapFallbackToFile("index.html"); + + app.Run(); + } } \ No newline at end of file diff --git a/src/TryMudBlazor.Server/Startup.cs b/src/TryMudBlazor.Server/Startup.cs deleted file mode 100644 index bdfb19a2..00000000 --- a/src/TryMudBlazor.Server/Startup.cs +++ /dev/null @@ -1,63 +0,0 @@ -using MudBlazor.Examples.Data; - -namespace TryMudBlazor.Server; - -public class Startup -{ - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddScoped(); - services.AddCors(options => - { - options.AddDefaultPolicy( - builder => - { - builder.WithOrigins("https://www.mudblazor.com", "https://mudblazor.com"); - }); - }); - - services.AddControllers(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseCors(); - - // Needed for wasm project - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - - // Serve the wasm project if no other matches - endpoints.MapFallbackToFile("index.html"); - }); - } -} \ No newline at end of file