From fef79ffe85c066d1c42d353622a6d9e2a612032a Mon Sep 17 00:00:00 2001 From: Tomi Parviainen Date: Sat, 23 Dec 2023 22:13:25 +0200 Subject: [PATCH] Use top-level statements for Blazor app --- src/ClashOfClans.Blazor/Program.cs | 58 ++++++++++++++++++---------- src/ClashOfClans.Blazor/Startup.cs | 61 ------------------------------ 2 files changed, 38 insertions(+), 81 deletions(-) delete mode 100644 src/ClashOfClans.Blazor/Startup.cs diff --git a/src/ClashOfClans.Blazor/Program.cs b/src/ClashOfClans.Blazor/Program.cs index 4a316da8..ba70c415 100644 --- a/src/ClashOfClans.Blazor/Program.cs +++ b/src/ClashOfClans.Blazor/Program.cs @@ -1,26 +1,44 @@ +using ClashOfClans.Core; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.PlatformAbstractions; -namespace ClashOfClans.Blazor +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorPages(); +builder.Services.AddServerSideBlazor(); +builder.Services.AddClashOfClans(options => +{ + var clashOptions = new ClashOfClansOptionsV2(); + builder.Configuration.GetSection(ClashOfClansOptions.ClashOfClans).Bind(clashOptions); + + options.Tokens.AddRange(clashOptions.Tokens); + options.MaxRequestsPerSecond = clashOptions.MaxRequestsPerSecond; +}); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.SetBasePath(PlatformServices.Default.Application.ApplicationBasePath); - }) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseDeveloperExceptionPage(); } +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.UseStaticFiles(); + +app.UseRouting(); +app.UseAuthorization(); + +app.MapDefaultControllerRoute(); +app.MapRazorPages(); +app.MapBlazorHub(); + +app.Run(); diff --git a/src/ClashOfClans.Blazor/Startup.cs b/src/ClashOfClans.Blazor/Startup.cs deleted file mode 100644 index 0ffa85e5..00000000 --- a/src/ClashOfClans.Blazor/Startup.cs +++ /dev/null @@ -1,61 +0,0 @@ -using ClashOfClans.Core; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace ClashOfClans.Blazor -{ - 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. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - services.AddRazorPages(); - services.AddServerSideBlazor(); - services.AddClashOfClans(options => - { - var clashOptions = new ClashOfClansOptionsV2(); - Configuration.GetSection(ClashOfClansOptions.ClashOfClans).Bind(clashOptions); - - options.Tokens.AddRange(clashOptions.Tokens); - options.MaxRequestsPerSecond = clashOptions.MaxRequestsPerSecond; - }); - } - - // 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(); - } - 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.UseStaticFiles(); - - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapBlazorHub(); - endpoints.MapFallbackToPage("/_Host"); - }); - } - } -}