Aspnetcore: Load Configuration On Application Startup from Backed (Blazor WebAssembly)

Created on 1 Apr 2020  路  3Comments  路  Source: dotnet/aspnetcore

We want to load Configuration from the server api and based on this configuration we want to configure our DI. So, we probably need to make a http call. In order to do this http call we need the DI configured so we can get a HttpClient. But DI is not configured, so we can't use HttpClient.

It would be nice to use the javascript to make this call, but we can't use IJSRuntime because it is also created after the DI is configured. (#5664, #5664)

So, can you provide a nice way that we can load Configuration Options On Application Startup before the DI is configured?

Answered Resolved area-blazor blazor-wasm question

Most helpful comment

@xrkolovos thanks for contacting us.

You can new-up an instance of HttpClient and the base url is available on the WebassemblyHostBuilder as part of preview3.

All 3 comments

@xrkolovos thanks for contacting us.

You can new-up an instance of HttpClient and the base url is available on the WebassemblyHostBuilder as part of preview3.

@captainsafia Can you confirm here?

Unfortunately, this change is not available in preview3, but it will ship in preview4. The change will allow you to access the BaseAdress property from the builder to instantiate an HTTP client (builders.HostEnvironment.BaseAddress).

Was this page helpful?
0 / 5 - 0 ratings