Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration validation #31

Open
jakubfijalkowski opened this issue Jun 5, 2020 · 2 comments
Open

Configuration validation #31

jakubfijalkowski opened this issue Jun 5, 2020 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@jakubfijalkowski
Copy link
Member

We don't have any means to validate system-provided (e.g. env variables, KeyVault) configuration. Having such mechanisms would be beneficial, esp. for first time prod deployments (or when the config changes).

@marcin-dardzinski
Copy link
Member

Any idea how could we address it?
I have a few:

  1. For config registered in the DI we could use data annotations / fluent validation to validate, to some extent replicating what regular ASP.NET IOptions offer. It would have the benefit of reusability esp for the common packages (PushNotifications / SendGrid / KeyVault). But it won't work for configuration not injected to DI, e.g. connection strings.
  2. Some validation when reading data from IConfiguration e.g. when the requested key is not set, but it would be hard to cover all IConfiguration api surface.
  3. Some checks would have to be mandatory (and crash app on startup), but some would have to be optional and just trigger warning, e.g. to facilitate development/integration tests. Maybe it has to be dependent on the environment level - be strict on production, but only warn on dev/test.

@jakubfijalkowski
Copy link
Member Author

jakubfijalkowski commented Jun 9, 2020

Regarding your points

  1. I don't like that. Configuration validation is, IMO, responsibility of the app and not of the modules (it will be painful to modify the behavior). I don't think we should have DI involved here at all and we shouldn't use anything IOption-like.
  2. You don't need to use IConfiguration. We're already using custom Config class and that's all that we need to use to validate the configuration IMO.
  3. It has to be done differently on test/prod & on dev. I, for example, tend to use as few secrets as I can so that I'm not dependent on network access or just don't send unwanted e-mails.

Let's start small, with just a basic checks & some general rules regarding that (i.e. predefined exceptions/helper methods like EnsureExistsOnTest(Func<IConfiguration, string> getter)).

@jakubfijalkowski jakubfijalkowski added the enhancement New feature or request label Mar 28, 2022
@jakubfijalkowski jakubfijalkowski added this to the vNext milestone Feb 20, 2023
@jakubfijalkowski jakubfijalkowski modified the milestones: vNext, v7.1 Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants