The Problem
.NET Core has the IConfiguration abstraction out of the box. It also has the ability to read configuration from multiple sources such as JSON files, Environment Variables etc and one can easily write a custom configuration provider for getting configuration from another source (such as an HTTP endpoint). However, passing IConfiguration around your code base as a dependency (injected via constructor) has the downside of violating principle of interface segregation and least surprise.
This is because a reader of the code that accepts IConfiguration via constructor cannot quite tell which keys the code really requires. They would need to look for all calls to IConfiguration.GetValue (or similar) to understand what configuration is required for the class.
Andrew Lock:
- Adding Validation to strongly typed .NET config
- A startup filter for ASP.NET
- Andrew's Netescapades repo on github