-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
DoneThis issue has been fixedThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssembly
Milestone
Description
Application developers that need to resolve a resource from their app in Program.MainAsync have to build the IServiceCollection and resolve the NavigationManager from DI. We usually tell users not to build the service container. It would be much more convenient if the interface exposed the URI. In tandem with #19900, this would make doing things at startup much more reasonable. We could even consider removing the AddBaseAddressHttpClient extension method if this were available:
public sealed class WebAssemblyHostBuilder
{
/// <summary>Gets the <see cref="IWebAssemblyHostEnvironment" />.
+ public IWebAssemblyHostEnvironment HostEnvironment { get; }
}
public interface IWebAssemblyHostEnvironment
{
+ /// <summary> Gets the application base address</summary>
+ public Uri BaseAddress { get; }
}
// Blazor-wasm Template
public static async Task Main(...)
{
- builder.Services.AddBaseAddressHttpClient();
+ builder.Services.AddSingleton(new HttpClient { BaseAddress = builder.HostEnvironment.BaseAddress });
}The last bit might also play better with users having to configure a custom HttpMessageHandler on the HttpClient instance.
SteveSandersonMS
Metadata
Metadata
Assignees
Labels
DoneThis issue has been fixedThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssembly