diff --git a/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in index c6ddfee52e47..67cd7e941246 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in @@ -9,7 +9,6 @@ - diff --git a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in index ec9d1aa17b6e..8a9f8ed0e2e5 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in @@ -9,7 +9,6 @@ - diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs index 91d8b747cdc5..07d261f44762 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs @@ -1,27 +1,55 @@ namespace Company.WebApplication1 +#nowarn "20" + open System open System.Collections.Generic open System.IO open System.Linq open System.Threading.Tasks open Microsoft.AspNetCore +open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Hosting +#if !NoHttps +open Microsoft.AspNetCore.HttpsPolicy +#endif open Microsoft.Extensions.Configuration +open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Hosting open Microsoft.Extensions.Logging module Program = let exitCode = 0 - let CreateHostBuilder args = - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(fun webBuilder -> - webBuilder.UseStartup() |> ignore - ) - [] let main args = - CreateHostBuilder(args).Build().Run() + let builder = WebApplication.CreateBuilder(args) + + builder + .Services + .AddControllersWithViews() + .AddRazorRuntimeCompilation() + + builder.Services.AddRazorPages() + + let app = builder.Build() + + if not (builder.Environment.IsDevelopment()) then + app.UseExceptionHandler("/Home/Error") +#if !NoHttps + app.UseHsts() |> ignore // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + + app.UseHttpsRedirection() +#endif + + app.UseStaticFiles() + app.UseRouting() + app.UseAuthorization() + + app.MapControllerRoute(name = "default", pattern = "{controller=Home}/{action=Index}/{id?}") + + app.MapRazorPages() + + app.Run() exitCode diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs deleted file mode 100644 index 607ec13b55bf..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs +++ /dev/null @@ -1,55 +0,0 @@ -namespace Company.WebApplication1 - -open System -open System.Collections.Generic -open System.Linq -open System.Threading.Tasks -open Microsoft.AspNetCore.Builder -open Microsoft.AspNetCore.Hosting -#if (!NoHttps) -open Microsoft.AspNetCore.HttpsPolicy; -#endif -open Microsoft.AspNetCore.Mvc -open Microsoft.Extensions.Configuration -open Microsoft.Extensions.DependencyInjection -open Microsoft.Extensions.Hosting - -type Startup private () = - new (configuration: IConfiguration) as this = - Startup() then - this.Configuration <- configuration - - // This method gets called by the runtime. Use this method to add services to the container. - member this.ConfigureServices(services: IServiceCollection) = - // Add framework services. - services.AddControllersWithViews().AddRazorRuntimeCompilation() |> ignore - services.AddRazorPages() |> 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 - app.UseDeveloperExceptionPage() |> ignore - else - app.UseExceptionHandler("/Home/Error") |> ignore -#if (!NoHttps) - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts() |> ignore - - app.UseHttpsRedirection() |> ignore -#else - -#endif - app.UseStaticFiles() |> ignore - - app.UseRouting() |> ignore - - app.UseAuthorization() |> ignore - - app.UseEndpoints(fun endpoints -> - endpoints.MapControllerRoute( - name = "default", - pattern = "{controller=Home}/{action=Index}/{id?}") |> ignore - endpoints.MapRazorPages() |> ignore) |> ignore - - member val Configuration : IConfiguration = null with get, set diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs index 91d8b747cdc5..0593d5111bd0 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs @@ -1,27 +1,40 @@ namespace Company.WebApplication1 - +#nowarn "20" open System open System.Collections.Generic open System.IO open System.Linq open System.Threading.Tasks open Microsoft.AspNetCore +open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Hosting +#if !NoHttps +open Microsoft.AspNetCore.HttpsPolicy +#endif open Microsoft.Extensions.Configuration +open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Hosting open Microsoft.Extensions.Logging module Program = let exitCode = 0 - let CreateHostBuilder args = - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(fun webBuilder -> - webBuilder.UseStartup() |> ignore - ) - [] let main args = - CreateHostBuilder(args).Build().Run() + + let builder = WebApplication.CreateBuilder(args) + + builder.Services.AddControllers() + + let app = builder.Build() + +#if !NoHttps + app.UseHttpsRedirection() +#endif + + app.UseAuthorization() + app.MapControllers() + + app.Run() exitCode diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs deleted file mode 100644 index 1a44dc3b0868..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs +++ /dev/null @@ -1,42 +0,0 @@ -namespace Company.WebApplication1 - -open System -open System.Collections.Generic -open System.Linq -open System.Threading.Tasks -open Microsoft.AspNetCore.Builder -open Microsoft.AspNetCore.Hosting -#if (!NoHttps) -open Microsoft.AspNetCore.HttpsPolicy; -#endif -open Microsoft.AspNetCore.Mvc -open Microsoft.Extensions.Configuration -open Microsoft.Extensions.DependencyInjection -open Microsoft.Extensions.Hosting - -type Startup(configuration: IConfiguration) = - member _.Configuration = configuration - - // This method gets called by the runtime. Use this method to add services to the container. - member _.ConfigureServices(services: IServiceCollection) = - // Add framework services. - services.AddControllers() |> ignore - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - member _.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = - if (env.IsDevelopment()) then - app.UseDeveloperExceptionPage() |> ignore -#if (!NoHttps) - app.UseHttpsRedirection() - .UseRouting() - .UseAuthorization() - .UseEndpoints(fun endpoints -> - endpoints.MapControllers() |> ignore - ) |> ignore -#else - app.UseRouting() - .UseAuthorization() - .UseEndpoints(fun endpoints -> - endpoints.MapControllers() |> ignore - ) |> ignore -#endif diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index eb3859aabb05..b707dcd78819 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -631,7 +631,6 @@ "appsettings.Development.json", "appsettings.json", "Program.fs", - "Startup.fs", "WeatherForecast.fs", "Controllers/WeatherForecastController.fs", "Properties/launchSettings.json" @@ -1142,7 +1141,6 @@ "appsettings.Development.json", "appsettings.json", "Program.fs", - "Startup.fs", "Controllers/HomeController.fs", "Models/ErrorViewModel.fs", "Properties/launchSettings.json",