leaderboardsgg / leaderboard-backend

The backend for Leaderboards.gg. Also holds public-facing APIs.
https://info.leaderboards.gg
GNU General Public License v3.0
12 stars 16 forks source link

Strongly typed configuration + validation #134

Closed Dalet closed 1 year ago

Dalet commented 1 year ago

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, but ConfigObject could also be directly injected by also adding it as a singleton:

builder.Services.AddSingleton(services => services.GetRequiredService<IOptions<ConfigObject>>().Value);

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.