Skip to content

Inject settings thru environment variables #2169

Answered by sorbonad
sorbonad asked this question in Q&A
Discussion options

You must be logged in to vote

Ater browsing the code a little bit, I believe this would work:

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(GetJsonConfigFromEnvironmentVariables())));
...

GetJsonConfigFromEnvironmentVariables is just reading the env variable which contains a valid json config payload.

I believe this won't play nicely with the auto config hot reloads, but in my case that scenario is not going to happen since every configuration/code change requires a deployment.

What do you think?

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@sorbonad
Comment options

@Tratcher
Comment options

@sorbonad
Comment options

@sorbonad
Comment options

Answer selected by karelz
@Tratcher
Comment options

@sorbonad
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants