diff options
author | Phillip Carter <pcarter@fastmail.com> | 2020-05-16 21:18:44 +0300 |
---|---|---|
committer | Phillip Carter <pcarter@fastmail.com> | 2020-05-16 21:18:44 +0300 |
commit | c147d57398b91f4947e2fce0ae8f31433a1e9273 (patch) | |
tree | 4dbdb89f0b467ada87d770de5aca74e0bdc6f9ba /src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp | |
parent | ff773bd843924e73de1d1d0156b1839335ec391e (diff) |
Update F# web templates to be more idiomatic
Diffstat (limited to 'src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp')
3 files changed, 34 insertions, 25 deletions
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherForecastController.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherForecastController.fs index 45c42e8e12..d701ce64f9 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherForecastController.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherForecastController.fs @@ -13,10 +13,22 @@ open Company.WebApplication1 type WeatherForecastController (logger : ILogger<WeatherForecastController>) = inherit ControllerBase() - let summaries = [| "Freezing"; "Bracing"; "Chilly"; "Cool"; "Mild"; "Warm"; "Balmy"; "Hot"; "Sweltering"; "Scorching" |] + let summaries = + [| + "Freezing" + "Bracing" + "Chilly" + "Cool" + "Mild" + "Warm" + "Balmy" + "Hot" + "Sweltering" + "Scorching" + |] [<HttpGet>] - member __.Get() : WeatherForecast[] = + member _.Get() = let rng = System.Random() [| for index in 0..4 -> diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs index 2a0ec457f8..1a44dc3b08 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs @@ -14,32 +14,29 @@ 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 +type Startup(configuration: IConfiguration) = + member _.Configuration = configuration // This method gets called by the runtime. Use this method to add services to the container. - member this.ConfigureServices(services: IServiceCollection) = + 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 this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = + member _.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = if (env.IsDevelopment()) then app.UseDeveloperExceptionPage() |> ignore #if (!NoHttps) - - app.UseHttpsRedirection() |> ignore + app.UseHttpsRedirection() + .UseRouting() + .UseAuthorization() + .UseEndpoints(fun endpoints -> + endpoints.MapControllers() |> ignore + ) |> ignore #else - + app.UseRouting() + .UseAuthorization() + .UseEndpoints(fun endpoints -> + endpoints.MapControllers() |> ignore + ) |> ignore #endif - app.UseRouting() |> ignore - - app.UseAuthorization() |> ignore - - app.UseEndpoints(fun endpoints -> - endpoints.MapControllers() |> ignore - ) |> ignore - - member val Configuration : IConfiguration = null with get, set diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/WeatherForecast.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/WeatherForecast.fs index 34e1d8e301..dbbf5971c3 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/WeatherForecast.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/WeatherForecast.fs @@ -3,9 +3,9 @@ namespace Company.WebApplication1 open System type WeatherForecast = - { Date: DateTime - TemperatureC: int - Summary: string } + { Date: DateTime + TemperatureC: int + Summary: string } - member this.TemperatureF = - 32 + (int (float this.TemperatureC / 0.5556)) + member this.TemperatureF = + 32.0 + (float this.TemperatureC / 0.5556) |