Azure / Azure/azure-functions-host

Can .NET5 isolated Azure Functions provide access to IWebhostEnvironment

Open
#7,269 3 comments 7 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

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 as `IWebhostEnvironment.IsDevelopment`.

What I found from my tests:

`IWebhostEnvironment` is not available for injection in Functions.

`IHostEnvironment` is available, but ignores the `ASPNETCORE_ENVIRONMENT` value set in local.settings.json, and therefore always returns `Production`.

Is there a way to make `IWebhostEnvironment` behave the same way in Azure Functions and ASP.NET Core? For now I have created my own `IFunctionHostEnvironment` interface that returns results based on the value of `Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT")`, which is automatically set to `Development` locally by Core Tools, and can be set manually in Azure portal.

Contributor guide

Open the contributing guide

Research direction

Start with the .NET 5 isolated Azure Functions DI setup described in the issue and compare how IHostEnvironment, IWebHostEnvironment, ASPNETCORE_ENVIRONMENT, and AZURE_FUNCTIONS_ENVIRONMENT are handled. Done means determining whether IWebHostEnvironment can be injected with the expected environment value, or documenting the supported equivalent when it cannot.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.