Skip to content

Commit 936c11b

Browse files
authored
[Preview 4] Blazor WASM HostEnvironment (#17856)
1 parent ccab8c4 commit 936c11b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

aspnetcore/blazor/hosting-model-configuration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ Obtain the app's environment in a component by injecting `IWebAssemblyHostEnviro
6060
<p>Environment: @HostEnvironment.Environment</p>
6161
```
6262

63+
During startup, the `WebAssemblyHostBuilder` exposes the `IWebAssemblyHostEnvironment` through the `HostEnvironment` property, which enables developers to have environment-specific logic in their code:
64+
65+
```csharp
66+
if (builder.HostEnvironment.Environment == "Custom")
67+
{
68+
...
69+
};
70+
```
71+
72+
The following convenience extension methods permit checking the current environment for Development, Production, Staging, and custom environment names:
73+
74+
* `IsDevelopment()`
75+
* `IsProduction()`
76+
* `IsStaging()`
77+
* `IsEnvironment("{ENVIRONMENT NAME}")
78+
79+
```csharp
80+
if (builder.HostEnvironment.IsStaging())
81+
{
82+
...
83+
};
84+
85+
if (builder.HostEnvironment.IsEnvironment("Custom"))
86+
{
87+
...
88+
};
89+
```
90+
91+
The `IWebAssemblyHostEnvironment.BaseAddress` property can be used during startup when the `NavigationManager` service isn't available.
92+
6393
### Configuration
6494

6595
As of the ASP.NET Core 3.2 Preview 3 release ([current release is 3.2 Preview 4](xref:blazor/get-started)), Blazor WebAssembly supports configuration from:

0 commit comments

Comments
 (0)