How to get configurations variables?
I'm new to asp.net, been trying to create some apis.
For now, I'm trying to get the db connection string, out of the
appsettings.json
. Is that possible or would I need to use something like .env
variables with some extra configuration?3 Replies
Did you try to search tho?
But yes, you can get values from appsettings...
https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings?source=recommendations#aspnet-core
yea, was seeing that, just didn't know where the Configuration class was
thx
Now I'm just having the good'ol migrations and db problem
IConfiguration is added automatically behind the scenes to the container (for Dependency Injection).
It loads configurations/values from various sources, overriding previous values depending on what source has higher priority. You can read more about it here:
- https://learn.microsoft.com/en-us/dotnet/core/extensions/configuration#concepts-and-abstractions