Skip to content

Commit 8a1974d

Browse files
[release/6.0-rc2] Use minimal APIs for F# project templates (#36660)
1 parent 49a2202 commit 8a1974d

File tree

7 files changed

+56
-116
lines changed

7 files changed

+56
-116
lines changed

src/ProjectTemplates/Web.ProjectTemplates/StarterWeb-FSharp.fsproj.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<ItemGroup>
1010
<Compile Include="Models/ErrorViewModel.fs" />
1111
<Compile Include="Controllers/HomeController.fs" />
12-
<Compile Include="Startup.fs" />
1312
<Compile Include="Program.fs" />
1413
</ItemGroup>
1514

src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<ItemGroup>
1010
<Compile Include="WeatherForecast.fs" />
1111
<Compile Include="Controllers/WeatherForecastController.fs" />
12-
<Compile Include="Startup.fs" />
1312
<Compile Include="Program.fs" />
1413
</ItemGroup>
1514

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
11
namespace Company.WebApplication1
22

3+
#nowarn "20"
4+
35
open System
46
open System.Collections.Generic
57
open System.IO
68
open System.Linq
79
open System.Threading.Tasks
810
open Microsoft.AspNetCore
11+
open Microsoft.AspNetCore.Builder
912
open Microsoft.AspNetCore.Hosting
13+
#if !NoHttps
14+
open Microsoft.AspNetCore.HttpsPolicy
15+
#endif
1016
open Microsoft.Extensions.Configuration
17+
open Microsoft.Extensions.DependencyInjection
1118
open Microsoft.Extensions.Hosting
1219
open Microsoft.Extensions.Logging
1320

1421
module Program =
1522
let exitCode = 0
1623

17-
let CreateHostBuilder args =
18-
Host.CreateDefaultBuilder(args)
19-
.ConfigureWebHostDefaults(fun webBuilder ->
20-
webBuilder.UseStartup<Startup>() |> ignore
21-
)
22-
2324
[<EntryPoint>]
2425
let main args =
25-
CreateHostBuilder(args).Build().Run()
26+
let builder = WebApplication.CreateBuilder(args)
27+
28+
builder
29+
.Services
30+
.AddControllersWithViews()
31+
.AddRazorRuntimeCompilation()
32+
33+
builder.Services.AddRazorPages()
34+
35+
let app = builder.Build()
36+
37+
if not (builder.Environment.IsDevelopment()) then
38+
app.UseExceptionHandler("/Home/Error")
39+
#if !NoHttps
40+
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.
41+
42+
app.UseHttpsRedirection()
43+
#endif
44+
45+
app.UseStaticFiles()
46+
app.UseRouting()
47+
app.UseAuthorization()
48+
49+
app.MapControllerRoute(name = "default", pattern = "{controller=Home}/{action=Index}/{id?}")
50+
51+
app.MapRazorPages()
52+
53+
app.Run()
2654

2755
exitCode

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
namespace Company.WebApplication1
2-
2+
#nowarn "20"
33
open System
44
open System.Collections.Generic
55
open System.IO
66
open System.Linq
77
open System.Threading.Tasks
88
open Microsoft.AspNetCore
9+
open Microsoft.AspNetCore.Builder
910
open Microsoft.AspNetCore.Hosting
11+
#if !NoHttps
12+
open Microsoft.AspNetCore.HttpsPolicy
13+
#endif
1014
open Microsoft.Extensions.Configuration
15+
open Microsoft.Extensions.DependencyInjection
1116
open Microsoft.Extensions.Hosting
1217
open Microsoft.Extensions.Logging
1318

1419
module Program =
1520
let exitCode = 0
1621

17-
let CreateHostBuilder args =
18-
Host.CreateDefaultBuilder(args)
19-
.ConfigureWebHostDefaults(fun webBuilder ->
20-
webBuilder.UseStartup<Startup>() |> ignore
21-
)
22-
2322
[<EntryPoint>]
2423
let main args =
25-
CreateHostBuilder(args).Build().Run()
24+
25+
let builder = WebApplication.CreateBuilder(args)
26+
27+
builder.Services.AddControllers()
28+
29+
let app = builder.Build()
30+
31+
#if !NoHttps
32+
app.UseHttpsRedirection()
33+
#endif
34+
35+
app.UseAuthorization()
36+
app.MapControllers()
37+
38+
app.Run()
2639

2740
exitCode

src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/ProjectTemplates/test/template-baselines.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@
631631
"appsettings.Development.json",
632632
"appsettings.json",
633633
"Program.fs",
634-
"Startup.fs",
635634
"WeatherForecast.fs",
636635
"Controllers/WeatherForecastController.fs",
637636
"Properties/launchSettings.json"
@@ -1142,7 +1141,6 @@
11421141
"appsettings.Development.json",
11431142
"appsettings.json",
11441143
"Program.fs",
1145-
"Startup.fs",
11461144
"Controllers/HomeController.fs",
11471145
"Models/ErrorViewModel.fs",
11481146
"Properties/launchSettings.json",

0 commit comments

Comments
 (0)