C#C
C#15mo ago
Camster

User Secrets in Blazor Web Assembly

I have a Blazor Web Assembly app that can connect to a production API on the web or a development API on the local machine. The Program.cs file looks like this:
builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://www.productionapi.com", x));
//builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://localhost:1234", x));


Whenever I want to switch between the two, I have to edit the file, and sometimes I forgot I need to undo the change before checking in.

My question is: Is it possible to use User Secrets to make this easy switch while I'm testing? I can already to that in other code bases, but since this is Web Assembly and doesn't have AppSettings, I'm not sure how to do it here.

Thank you for your help.
image.png
Was this page helpful?