Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Access to configuration without dependency injection

$
0
0

I was wondering if there was a way to access Configuration (Microsoft.Extensions.Configuration) without the use of dependency injection. Only examples I see are through constructor injection (using IOptions or injecting Configuration directly) via Startup.

My dilemma is that I have a utility class-- not a service-- that has static methods to do things on the fly. In a few of those static methods I would like to retrieve a couple of properties from appsettings.json dynamically.  These properties contain values I don't want to hard code in the utility class and can be configured differently depending on the deployment.  Since this is strictly a utility class with no interface and such, I don't want have to inject this class into every other class that needs to use a method or two from the utility.

Any ideas on how to access the properties of appsettings.json without some sort of dependency injection.

FYI: using c# and .net core 1.1


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>