SaturnFramework / Saturn

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

How to externalize configuration information #359

Closed scorelocity closed 1 year ago

scorelocity commented 1 year ago

Is there an idiomatic way in Saturn to externalize configuration information, such as connection strings, so that it can be different in different environments, such as development, staging and production? The Saturn template has a connection string hard-coded in Program.fs and I don't see any other suggestions in the documentation or samples.

I'm also confused on how I might use built-in dotnet core configuration approaches, appsettings, user secrets, environment variables, etc., in Saturn.

Banashek commented 1 year ago

A basic solution could just load in the items you want one by one. Dotnet comes with methods to access these plainly: https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=net-7.0

You could also give FsConfig a shot. Just replace the hardcoded libraries with that.

As noted, it supports Environment Variables, AppConfig, Json Files, INI files (similar to the typical .env found in other ecosystems), XML.

Also some notes in this blog post about env vars and .env files.

scorelocity commented 1 year ago

@Banashek - Thank you. Closing.