DEV Community

Discussion on: Typesafe F# configuration binding

Collapse
 
jkone27 profile image
jkone27 • Edited

if you try out the linked repo you should see one possible way of safely using type providers. Type providers usually define a Type (Class), not an object (instance), the instance can be bind at run time (with Load function in JsonProvider case).

let settingsFile = "appsettings." + 
     Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") + 
     ".json"
let config = AppSettingsProvider.Load(settingsFile)

services.AddSingleton<AppSettings>(config)
Enter fullscreen mode Exit fullscreen mode

If you talk about changing configuration once the app has started (unique of IOption), that doesn't happen no, but we happily lived without it before dotnetcore, in most of use-cases, I generarlly don't need that "option" functionality for apps.

weblog.west-wind.com/posts/2017/de...

For environment variables, they are automatically overridden in the json file by aspnetcore, if they have a matching pattern, so that is also already covered by aspnet and works fine as the file is loaded for each environment.

That's for example how you would inject secrets and sensitive config for example, that also works fine with type providers.