|
|
|
|
|
by Wolfspirit
3058 days ago
|
|
I'm not quite sure what you mean. There is no ConfigurationManager used in Asp.NET Core. Are you talking about IConfiguration? The reason why you want to have it injected as IOption<> is cause you might want to change configuration on the fly. If you do it right, there is no need for the app to restart if you change the appsettings.json at all. Also it makes things much more flexible and loosely coupled, for example third party middlewares can bring their own Settings and you can define which part of the whole appsettings.json is meant to be for that Middleware. There is also no need to pass it to the constructor and manage it yourself via a field inside your class, at least in your controllers. You can just use
the [FromServices] attribute before an action argument to inject it into just that method (and that works for properties deeper down the "callstack" aswell). |
|
I can see a case for mutable config, I use it, but the majority of config is not app time mutable and you shouldn't be designing a system for an edge case. Have a mutable config.
Experienced devs use the db for that by the way as mutable config generally needs an in app interface.