I'm working on a .NET 8 project to learn how to use minimal APIs, in the same project, that includes Blazor components. I don't know how to consume the minimal API in the project, so I asked Bing Copilot how to do that. In part, this is what it gave me that I should put into the Program.cs file:
builder.Services.AddRazorComponents();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
However, Visual Studio 2022 complains about builder.HostEnvironment.BaseAddress
. It says:
CS1061 'WebApplicationBuilder' does not contain a definition for 'HostEnvironment' and no accessible extension method 'HostEnvironment' accepting a first argument of type 'WebApplicationBuilder' could be found (are you missing a using directive or an assembly reference?
My guess is that section of code was valid in an older version of .NET but is no longer correct. I've tried rephrasing the question multiple times, but Bing Copilot continues to give me that code. So, my question is what should I use?