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/Web.ProjectTemplates/content/WebApi-FSharp | |
parent | a94189e39a5fdaf612bada2be7dd7e08a6a861cb (diff) |
Use minimal APIs for F# project templates (#35833)
Diffstat (limited to 'src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp')
-rw-r--r-- | src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Program.fs | 28 | ||||
-rw-r--r-- | src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs | 42 |
2 files changed, 20 insertions, 50 deletions
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 |