Skip to content

Consider exposing the application url using IWebAssemblyHostEnvironment #19910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pranavkm opened this issue Mar 16, 2020 · 3 comments
Closed
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly

Comments

@pranavkm
Copy link
Contributor

pranavkm commented Mar 16, 2020

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.

@pranavkm pranavkm added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Mar 16, 2020
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Mar 17, 2020
@mkArtakMSFT mkArtakMSFT added this to the blazor-wasm-3.2-preview4 milestone Mar 17, 2020
@Tratcher
Copy link
Member

Where would this get populated from?

@pranavkm
Copy link
Contributor Author

This is the Blazor Wasm specific host environment. The app is hosted at where the browser is pointing at, and we know this value from the browser.

@captainsafia captainsafia self-assigned this Mar 19, 2020
captainsafia added a commit that referenced this issue Mar 23, 2020
- Adds `BaseAddress` to `IWebAssemblyHostEnvironment`
- Uses unmarshalled APIs to extract application host
- Move NavigationManager initialization to startup code
- Fix subdir mapping in ClientSideHostingTest

Addresses #19910
@captainsafia
Copy link
Member

Closed via #20019.

ghost pushed a commit that referenced this issue Mar 25, 2020
* Restore public API contract on WebAssemblyJSRuntime (#19968)

* Shrink icon-512.png (#19999)

* Use custom DebugProxyHost to initialize DebugProxy config (#19980)

Addresses #19909

* Spruce up WebAssemblyHostEnvironment interface and use (#20008)

* Load .dlls/.wasm/.pdb in parallel with dotnet.*.js. Fixes #18898 (#20029)

* Add BaseAddress property to WebAssemblyHostEnvironment (#20019)

- Adds `BaseAddress` to `IWebAssemblyHostEnvironment`
- Uses unmarshalled APIs to extract application host
- Move NavigationManager initialization to startup code
- Fix subdir mapping in ClientSideHostingTest

Addresses #19910

Co-authored-by: Steve Sanderson <[email protected]>
Co-authored-by: Safia Abdalla <[email protected]>
Co-authored-by: Safia Abdalla <[email protected]>
@mkArtakMSFT mkArtakMSFT added the Done This issue has been fixed label Mar 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

4 participants