I have a .net core 8 app. It’s a multi object layered DLL architecture. From top to bottom my architecture looks like this.
- “Simple” web rest api
- DLL business logic code layer
- DLL Entities and TO’s
- DLL DbContext code layer
My Web rest API is NOT MVC, it’s using the “Simple” api approach, so no dependency injection and all that… At least not that I know how to do anyway.
My DbContext codebase is in it’s own separate DLL which gets compiled and deployed with the Web rest api. How do I read in the appsettings.json file so that I can store my db connection string?
In my appSettings.json I’d like to store multiple connection strings, one for each environment ( Dev, Test, Prod )…
I’d also like to store a value that indicates which environment it’s running in so I can pull out the proper connection string to connect to the correct DB.
In my Web api code base this works and I will get my connection string.
string conStr = app.Configuration.GetConnectionString("DB_CON_DEV");
But, I’m not able to find an equivalent to this approach in my codebase that uses the DbContext to get the connectionstring. I read something about a ConfigurationManager class and tried this, but it just returns null
ConfigurationManager cm = new ConfigurationManager();
string conStr = cm.GetConnectionString("DB_CON_DEV");
Any, help will be greatly appreciated!
Thanks
Rick