However, setting up configuration values is error-prone.
Here are just a few things that can go wrong:
- Passing an incorrect section name to IConfiguration.GetSection
- Forgetting to add the settings values in appsettings.json
- Typo in a property name in the class or the configuration
- Data type mismatch resulting in incompatible values
- Unbindale properties without a setter
The application will behave differently at runtime depending on which one of these mistakes is made.
The best-case scenario is that the incorrect application settings cause a runtime exception.
You realize you have a problem and fix it.
The worst-case scenario is that the application silently fails.
The problem may go undetected for some time.
Data annotations are a simple way to introduce validation to the settings class.
However, you can also integrate FluentValidation using the IValidateOptions interface.
If you liked this, consider joining The .NET Weekly - my newsletter with 29,000+ engineers.
Join us here โ
Are you using the Options pattern?
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
You can scale each database independently when using separate read and write databases. This is particularly useful when your application's queries lean heavily to one side.
HttpClient is an excellent abstraction and incredibly easy to work with.
Unfortunately, it's also easy to misuse, leading to problems like port exhaustion.
You need to know how NOT to use it.
If you think IHttpClientFactory will solve all your problems, you're only partly right.
Should you use named clients or typed clients?
Microsoft was kind enough to provide us with a set of best practices and recommended use for HttpClient.
- Use a static or singleton HttpClient instance with a PooledConnectionLifetime configured since this solves both port exhaustion and tracking DNS changes
A class should have only one reason to change. In other words, a class should have a single, well-defined responsibility. That class should entirely encapsulate responsibility.