C
C#3mo 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));
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.
No description
3 Replies
Camster
CamsterOP3mo ago
Heading to bed, I'll respond to any inquiries in the morning. Thank you
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Camster
CamsterOP3mo ago
I don't have an appsettings file in my blazor project, but you think I can just add it and it should work? I'll give it a try, thank you! I'm using a client generated by nswagstudio, so that's why it's slightly different Oh I see what you mean. It should already have created a new instance of Client. Okay, I'll take a look at that too
Want results from more Discord servers?
Add your server