How do you configure a per-environment appsettings.json config in a Blazor client application?

Viewed 263

I have a client app in blazor that connects to a server. When I'm running it on my local machine in dev, the server's hostname is dev.someurl.com

When it's live it's live.someurl.com

I've set up injection of IConfiguration which loads appsettings.Development.json automatically, however I can't change the environment. The docs say that when published it will use appsettings.Production.json however this is not the case as I've published it under Release build and seen that.

The environment appears to be readonly. With a signalr .net core app I can do this:

return Host.CreateDefaultBuilder(args).UseEnvironment(environmentName)

However with a blazor client application you have this:

var builder = WebAssemblyHostBuilder.CreateDefault(args);

The builder lets you access HostEnvironment but you cannot modify it.

The reading of the appsettings config file is all automatic, built in with this code:

builder.Services.AddSingleton(provider =>
{
    var config = provider.GetService<IConfiguration>();
    return config;
});

Any ideas how I can get around this?

Being a blazor client app you can apparently set the environment in a header, but I can't figure out how to do that programatically. Ideas welcome.

0 Answers
Related