diff options
author | Vlad Zarytovskii <vzaritovsky@hotmail.com> | 2021-09-17 21:13:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 21:13:01 +0300 |
commit | ba0242544a5e8568853239e3f40cfc87bad61596 (patch) | |
tree | 4c84d9c3e0c54cc97e771fe1958178e7e282512f /src/ProjectTemplates | |
parent | a94189e39a5fdaf612bada2be7dd7e08a6a861cb (diff) |
Use minimal APIs for F# project templates (#35833)
Diffstat (limited to 'src/ProjectTemplates')
7 files changed, 55 insertions, 116 deletions
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in index c6ddfee52e..67cd7e9412 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in @@ -9,7 +9,6 @@ <ItemGroup> <Compile Include="Models/ErrorViewModel.fs" /> <Compile Include="Controllers/HomeController.fs" /> - <Compile Include="Startup.fs" /> <Compile Include="Program.fs" /> </ItemGroup> diff --git a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in index ec9d1aa17b..8a9f8ed0e2 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in @@ -9,7 +9,6 @@ <ItemGroup> <Compile Include="WeatherForecast.fs" /> <Compile Include="Controllers/WeatherForecastController.fs" /> - <Compile Include="Startup.fs" /> <Compile Include="Program.fs" /> </ItemGroup> diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Program.fs index 91d8b747cd..07d261f447 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<Startup>() |> ignore - ) - [<EntryPoint>] 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 607ec13b55..0000000000 --- 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 91d8b747cd..1abd303321 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs @@ -1,12 +1,16 @@ 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.Hosting open Microsoft.Extensions.Logging @@ -14,14 +18,22 @@ open Microsoft.Extensions.Logging module Program = let exitCode = 0 - let CreateHostBuilder args = - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(fun webBuilder -> - webBuilder.UseStartup<Startup>() |> ignore - ) - [<EntryPoint>] 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 1a44dc3b08..0000000000 --- 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 eb3859aabb..b707dcd788 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", |