From e078ceaec20f6ae3fb55ead3f8c0f647e996de8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Sun, 17 Dec 2023 18:35:44 +0100 Subject: [PATCH 1/2] [#46] Use Minimal API on the server side --- .../src/Bolero.Template.1.Server/Startup.fs | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/content/application/src/Bolero.Template.1.Server/Startup.fs b/content/application/src/Bolero.Template.1.Server/Startup.fs index 60d649a..43753b7 100644 --- a/content/application/src/Bolero.Template.1.Server/Startup.fs +++ b/content/application/src/Bolero.Template.1.Server/Startup.fs @@ -14,38 +14,37 @@ open Bolero.Template._1 open Bolero.Templating.Server //#endif -type Startup() = +module Program = + + [] + let main args = + let builder = WebApplication.CreateBuilder(args) - // 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 - member this.ConfigureServices(services: IServiceCollection) = //#if (hostpage == "razor") - services.AddMvc().AddRazorRuntimeCompilation() |> ignore + builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore //#else - services.AddMvc() |> ignore + builder.Services.AddMvc() |> ignore //#endif - services.AddServerSideBlazor() |> ignore - services + builder.Services.AddServerSideBlazor() |> ignore //#if (!minimal) - .AddAuthorization() + builder.Services.AddAuthorization() .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) - .AddCookie() - .Services - .AddBoleroRemoting() + .AddCookie() + |> ignore + builder.Services.AddBoleroRemoting() |> ignore //#endif //#if (hostpage != "html") - .AddBoleroHost() + builder.Services.AddBoleroHost() |> ignore //#endif //#if (hotreload_actual) #if DEBUG - .AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client") + builder.Services.AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client") |> ignore #endif //#endif - |> ignore - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = - if env.IsDevelopment() then + let app = builder.Build() + + if app.Environment.IsDevelopment() then app.UseWebAssemblyDebugging() app @@ -54,33 +53,25 @@ type Startup() = .UseRouting() .UseAuthorization() .UseBlazorFrameworkFiles() - .UseEndpoints(fun endpoints -> + |> ignore + //#if (hotreload_actual) #if DEBUG - endpoints.UseHotReload() + app.UseHotReload() #endif //#endif - endpoints.MapBoleroRemoting() |> ignore + app.MapBoleroRemoting() |> ignore //#if (hostpage == "razor") - endpoints.MapBlazorHub() |> ignore - endpoints.MapFallbackToPage("/_Host") |> ignore) + app.MapBlazorHub() |> ignore + app.MapFallbackToPage("/_Host") |> ignore //#elseif (hostpage == "bolero") - endpoints.MapBlazorHub() |> ignore - endpoints.MapFallbackToBolero(Index.page) |> ignore) + app.MapBlazorHub() |> ignore + app.MapFallbackToBolero(Index.page) |> ignore //#elseif (hostpage == "html") - endpoints.MapControllers() |> ignore - endpoints.MapFallbackToFile("index.html") |> ignore) + app.MapControllers() |> ignore + app.MapFallbackToFile("index.html") |> ignore //#endif |> ignore -module Program = - - [] - let main args = - WebHost - .CreateDefaultBuilder(args) - .UseStaticWebAssets() - .UseStartup() - .Build() - .Run() + app.Run() 0 From 18101819a4d7bec2a3a7174ef3d2ffe63c48429d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Sun, 17 Dec 2023 18:38:17 +0100 Subject: [PATCH 2/2] Use a top-level Program module on the server side --- .../src/Bolero.Template.1.Server/Startup.fs | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/content/application/src/Bolero.Template.1.Server/Startup.fs b/content/application/src/Bolero.Template.1.Server/Startup.fs index 43753b7..8c7dd3b 100644 --- a/content/application/src/Bolero.Template.1.Server/Startup.fs +++ b/content/application/src/Bolero.Template.1.Server/Startup.fs @@ -1,4 +1,4 @@ -namespace Bolero.Template._1.Server +module Bolero.Template._1.Server.Program open Microsoft.AspNetCore open Microsoft.AspNetCore.Authentication.Cookies @@ -14,64 +14,62 @@ open Bolero.Template._1 open Bolero.Templating.Server //#endif -module Program = - - [] - let main args = - let builder = WebApplication.CreateBuilder(args) +[] +let main args = + let builder = WebApplication.CreateBuilder(args) //#if (hostpage == "razor") - builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore + builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore //#else - builder.Services.AddMvc() |> ignore + builder.Services.AddMvc() |> ignore //#endif - builder.Services.AddServerSideBlazor() |> ignore + builder.Services.AddServerSideBlazor() |> ignore //#if (!minimal) - builder.Services.AddAuthorization() - .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) - .AddCookie() - |> ignore - builder.Services.AddBoleroRemoting() |> ignore + builder.Services.AddAuthorization() + .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + .AddCookie() + |> ignore + builder.Services.AddBoleroRemoting() |> ignore //#endif //#if (hostpage != "html") - builder.Services.AddBoleroHost() |> ignore + builder.Services.AddBoleroHost() |> ignore //#endif //#if (hotreload_actual) #if DEBUG - builder.Services.AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client") |> ignore + builder.Services.AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client") |> ignore #endif //#endif - let app = builder.Build() + let app = builder.Build() - if app.Environment.IsDevelopment() then - app.UseWebAssemblyDebugging() + if app.Environment.IsDevelopment() then + app.UseWebAssemblyDebugging() - app - .UseAuthentication() - .UseStaticFiles() - .UseRouting() - .UseAuthorization() - .UseBlazorFrameworkFiles() - |> ignore + app + .UseAuthentication() + .UseStaticFiles() + .UseRouting() + .UseAuthorization() + .UseBlazorFrameworkFiles() + |> ignore //#if (hotreload_actual) #if DEBUG - app.UseHotReload() + app.UseHotReload() #endif //#endif - app.MapBoleroRemoting() |> ignore + app.MapBoleroRemoting() |> ignore //#if (hostpage == "razor") - app.MapBlazorHub() |> ignore - app.MapFallbackToPage("/_Host") |> ignore + app.MapBlazorHub() |> ignore + app.MapFallbackToPage("/_Host") |> ignore //#elseif (hostpage == "bolero") - app.MapBlazorHub() |> ignore - app.MapFallbackToBolero(Index.page) |> ignore + app.MapBlazorHub() |> ignore + app.MapFallbackToBolero(Index.page) |> ignore //#elseif (hostpage == "html") - app.MapControllers() |> ignore - app.MapFallbackToFile("index.html") |> ignore + app.MapControllers() |> ignore + app.MapFallbackToFile("index.html") |> ignore //#endif - |> ignore + |> ignore - app.Run() - 0 + app.Run() + 0