In the startup file I need a way to access IConfiguration in another project. I have been told the Business Logic should not know about IConfiguration. If thats the case then how do I inject data from appsettings down to the business logic projects.
appsettings.json
{
"AdminEmail": "myemail@gmail.com"
}
How would I access AdminEmail in a class library I created in the same solution?
You can use
Microsoft.Extensions.Configuration
to achieve this. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration1 - Create a model for the settings
2 - Configure it on Startup.cs
3 - Use DI in your class library to retrieve the settings
Define a model for settings
Configure settings
Inject and use it
You could inject it quite easily: