Created
July 30, 2020 16:42
-
-
Save conficient/aca15e92931a15d76047cee598df2e0c to your computer and use it in GitHub Desktop.
Blazor DevOnly component - only show the content of the component in Development mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Microsoft.Extensions.Hosting | |
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment env | |
@if (isDevelopment) | |
{ | |
@ChildContent | |
} | |
@code { | |
[Parameter] public RenderFragment ChildContent { get; set; } | |
bool isDevelopment = false; | |
protected override void OnInitialized() | |
{ | |
isDevelopment = env.IsDevelopment(); | |
} | |
} |
Dang, I was just starting to write a 'DevOnly' component, (same name exactly!), and was wondering if I could inject IWebHostEnvironment.
Thanks :)
Edit:
In WASM I needed to inject this instead, but it works all the same:
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
@inject IWebAssemblyHostEnvironment env
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: