SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
714 stars 108 forks source link

application app_config must provide IHostingEnvironment #163

Closed xperiandri closed 4 years ago

xperiandri commented 5 years ago

How to convert this code into Saturn compliant?

if (env.IsDevelopment()) then
    app.UseDeveloperExceptionPage() |> ignore
else
    // 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
Krzysztof-Cieslak commented 5 years ago

It's really good question ^_^

xperiandri commented 5 years ago

Also ILogger created from ILoggerFactory would be useful

NinoFloris commented 5 years ago

These and other questions at some point pushed me to abandon application {} and just use raw webhostbuilder.

However now that panesofglass found an overload trick for custom CE operations we could add all the missing overloads.

xperiandri commented 5 years ago

@NinoFloris could you explain or post an excerpt of code?

antonburger commented 5 years ago

@NinoFloris could you explain or post an excerpt of code?

Seems to be referred to here: #164.

with original sources here and here.

I'm still going over the mechanism myself.

Krzysztof-Cieslak commented 4 years ago

To answer the original question - this should work fine:

app_config (fun app ->
    let env = app.ApplicationServices.GetService<IWebHostEnvironment >()
    if (env.IsDevelopment()) then
        app.UseDeveloperExceptionPage()
    else
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts()
)

Saturn 0.14 will include some helper to replace app.ApplicationServices.GetService<IWebHostEnvironment >() call with something more user friendly.