Open felinepc opened 3 years ago
@soninaren / @fabiocav , Please share your inputs here. Are there any alternative ways for the above scenario? can this be added as a feature request?
Same issue except using the HostBuilderContext. context.HostingEnvironment is always Production. Used the same workaround.
I'm also missing this feature. Was trying to use code from our older Asp.Net Core based Functions and now I cannot inject IWebHostEnvironment to our custom telemetry class as in our codebase. Not happy to create a custom IFunctionHostEnvironment workaround, I'd prefer a built-in and supported way of accessing environment in .NET 6 based Functions V4. Please advice.
I have been using the .NET 5 Azure Functions with the help of the official doc. So DI in the .NET 5 Azure Functions behaves much like the regular ASP.NET Core's DI, which is nice because it allows me to share libraries with other ASP.NET Core web apps.
But one thing I'm trying to figure out is the access to
IWebhostEnvironment
, which is available by default in ASP.NET Core. I have libraries taking this as a dependency to define some behaviors based on checks such asIWebhostEnvironment.IsDevelopment
.What I found from my tests:
IWebhostEnvironment
is not available for injection in Functions.IHostEnvironment
is available, but ignores theASPNETCORE_ENVIRONMENT
value set in local.settings.json, and therefore always returnsProduction
.Is there a way to make
IWebhostEnvironment
behave the same way in Azure Functions and ASP.NET Core? For now I have created my ownIFunctionHostEnvironment
interface that returns results based on the value ofEnvironment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT")
, which is automatically set toDevelopment
locally by Core Tools, and can be set manually in Azure portal.