I have a shared .NET Standard library that was originally being referenced by a .NET 4.8 MVC 4 project. There is a lot of code in this shared library that uses the ConfigurationManager
, like:
var sze = ConfigurationManager.AppSettings["MaxAttachmentSize"];
This value for MaxAttachmentSize
(and others) was being stored in the web.config
.
Now I have a .NET 6 project that I'm building, which will use this same shared project, and I need to find a way to make these configuration app settings work in the new .NET Core application. What's the best way to do this?
My questions I guess are:
- Is there a way to get
ConfigurationManager
to read from the .NET Core'sappsettings.json
file like it reads fromweb.config
in the ASP.NET MVC 4 project? - If not, is there another configuration reader that I can use instead that will do double duty being able to work for both projects like I need?
The big spanner in the works though is the fact that all calls to ConfigurationManger
right now are static, so if the .NET Core option could be static as well that would be incredibly helpful. If not, it'll just be more work moving the ASP.NET MVC 4 project to make those settings dependency injection available.