Refactored configuration to use the Options pattern
Added configuration for db migration (will be useful for the dev env deployment)
Changed the dotenv nuget to add dotenv as a configuration provider (only in Development env)
Options pattern
Going forward all new configuration should be strongly typed and validated.
The main benefit of using the Options pattern is configuration validation.
Note that here I've injected it as IOptions<ConfigObject> in services, but ConfigObject could also be directly injected by also adding it as a singleton:
Injecting as IOptions<> introduces a dependency on Microsoft.Extensions.Options in services. Let me know if you have an opinion about this.
I've removed direct env vars readings and made it rely the framework's configuration system instead.
By default ASP.NET already loads environment variables, but with a specific format (see example.env for updated env var names)
POSTGRES_TEST_PORT configuration
I plan on removing this config when I add Testcontainers to integration tests in a future PR. A test DB container will automatically be created and binded to a random available port.
I might have missed other configurations, let me know in that case.
Changes:
Options pattern
Going forward all new configuration should be strongly typed and validated.
The main benefit of using the Options pattern is configuration validation.
Note that here I've injected it as
IOptions<ConfigObject>
in services, butConfigObject
could also be directly injected by also adding it as a singleton:Injecting as
IOptions<>
introduces a dependency onMicrosoft.Extensions.Options
in services. Let me know if you have an opinion about this.I've removed direct env vars readings and made it rely the framework's configuration system instead. By default ASP.NET already loads environment variables, but with a specific format (see
example.env
for updated env var names)POSTGRES_TEST_PORT
configurationI plan on removing this config when I add Testcontainers to integration tests in a future PR. A test DB container will automatically be created and binded to a random available port.
I might have missed other configurations, let me know in that case.