I'd like to use env.IsDevelopment()
to control what content I see on a Blazor page.
I could add a singleton to the Startup
class:
public static IWebHostEnvironment Env { get; private set; }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Env = env;
}
Or is there another way to access IWebHostEnvironment
(or Startup
) via an instance variable?
Turns out that I can do this with injection. I added the following on my page:
@using Microsoft.AspNetCore.Hosting;
@using Microsoft.Extensions.Hosting;
@inject IWebHostEnvironment Env
Which allowed me to do stuff like this:
@if ( Env.IsDevelopment() )
{
<div>Some content that I'm testing and don't want on the server yet</div>
}
Thanks @Nkosi!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With