❔ ASP.NET Core Environment Variables in Dependency Injection
Hello, I have a (probably) slightly dumb question. What's the correct/recommended way to inject an environment variable (like from docker-compose or similar) into a service class in ASP.NET Core? Googling somehow always points me toward "multiple environments" such as test/staging/prod, but that's not what I'm looking for. My hunch is that I'm supposed to do it in
Program.cs
Program.cs
when setting up DI, somehow.
In Spring I might do something like this to inject
MY_ENV_VAR
MY_ENV_VAR
as a
String
String
into
MyService
MyService
@Serviceclass MyService(@Value("${MY_ENV_VAR}") val myEnvVar: String) { ... }
@Serviceclass MyService(@Value("${MY_ENV_VAR}") val myEnvVar: String) { ... }