I have a service which is called within an Azure Function, and the service accesses IHostEnvironment via DI. Very standard, works as expected:
public TestService(IHostEnvironment hostEnvironment, IHttpClientFactory httpClientFactory, ILogger<TestService> logger)
{
this.hostEnvironment = hostEnvironment;
this.httpClientFactory = httpClientFactory;
this.logger = logger;
}
When the function is deployed, the IsDevelopment method always returns true, and logging shows that this.hostEnvironment.EnvironmentName is always Development. I've tried adding settings for DOTNET_CORE_ENVIRONMENT, ASPNET_CORE_ENVIRONMENT, and AZURE_FUNCTIONS_ENVIRONMENT. No matter what these settings are, IsDevelopment is always returning true.
What environment variable do I need to set so that IHostEnvironment reflects the correct environment?
/// <inheritdoc/>
public async Task<MemoryStream> GetAsync(Uri requestUri, CancellationToken cancellationToken)
{
if (this.hostEnvironment.IsDevelopment())
{
return new MemoryStream(Encoding.Default.GetBytes("Test content"));
}
else
{
//etc....
}
}