Monday, 4 March 2019
.net core making config accessible to all classes
in .net framework ConfigurationManager could be accessed anywhere. The .net core method of accessing configuration requires some setup, so rather than doing that on every class set it up once and add it to the services so can be accessed via dependancy injection.
* in the startup method get a IConfigurationRoot based on the config file
* add the IConfigurationRoot object to the services collection
* in a class that needs to access configuration, get a concrete class via DI
Save the value into a private var accessible to the entire class.
* Any code in the class can access config via the private var
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment