Open danroth27 opened 1 year ago
@danroth27 Would having an Environment component work?
The other thing to account for here, is that I don't know how much this matters in webassembly scenarios, since the root component (app component) is always going to be statically rendered, I am not sure we need something that uses IWebAssemblyHostEnvironment.Environment
as that is going to be relevant only when running in wasm, and its main use is to load the appropriate settings file.
Off the top of my head, I'd be tempted to solve this in a different way that may be more flexibile / customisable?
Instead of using an Environment tag helper / style approach to do conditional rendering, another approach would be:
Configure an Options class - i.e this will be bound to configuration thats loaded for the current environment (for web assembly hosting that would be based on IWebAssemblyHostEnvironment.Environment)
Your options class could then have meaningful properties to control various features of your app for example: "ShouldRenderFeatureX"
Additionally your options class could also have your own "EnvironmentName" configured for example "Dev"
You can now inject this options class wherever it's needed and do things ike
@if (EnvironmentOptions.EnvironmentName == "Dev")
{
}
@if (EnvironmentOptions.IsFeatureXEnabled)
{
}
This mechanism should work everywhere, it just all depennds on which config you bind the options class to.
@danroth27 Would having an Environment component work?
That was my initial thought as well. I'm not sure what it would do though in a Blazor Hybrid app.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
MVC & Razor Pages provide an environment tag helper for rendering different content based on the current environment. It doesn't look like we have a way to get the environment name in Blazor in a hosting model agnostic way. In Blazor WebAssembly apps you can find out the current environment using IWebAssemblyHostEnvironment.Environment. In Blazor Server apps you can find out the environment using IHostEnvironment.EnvironmentName. Perhaps we should add one?