On ASP.NET Web Forms I used to have an utility static class, called WebConfigSettings, where I had all the app settings read from my Web.config file (for example WebConfigSettings.DebugModeEnabled).
Is it a bad practice on MVC? Shall I prefer using a non-static class and inject it on my controllers using dependency injection? If yes, where shall I put the property on the controller? I have read on this post that I should not use base controllers.
On ASP.NET Web Forms I used to have an utility static class , called
Share
The problem with static classes is that you will be coupling your controllers with the .NET configuration system making them more difficult to unit test in isolation. You could have an
IConfigurationinterface containing the necessary properties you will need throughout your application as well as an implementation of this interface reading the values of the properties from the config file. Now all that’s left is to configure your favorite DI framework to inject the proper implementation of this interface into your controllers constructors. And in your unit tests you will be able to mock this interface.