We expose an IWebHostEnvironment property on the builder (WebApplicationBuilder.Environment) in order to support conditional service registration (for e.g. base on the current environment). That property is currently incorrect when it comes to configuring the the host via UseEnvironment or UseContentRoot (or any other setting that affects the host configuration). We should decide how to fix it or what to do about this.
PS: We also added the IWebHostEnvironment to allow various part of the ASP.NET Core stack that scan for assets based on application name to work. e.g. MVC https://github.com/dotnet/aspnetcore/blob/2e4274cb67c049055e321c18cc9e64562da52dcf/src/Mvc/Mvc.Core/src/DependencyInjection/MvcCoreServiceCollectionExtensions.cs#L81-L88)
class Program
{
static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseEnvironment("Staging");
builder.Host.UseContentRoot(@"C:\dev\git\FeatherHttp\samples\");
builder.Server.UseEnvironment("Testing");
builder.Server.UseContentRoot(@"C:\dev\git\FeatherHttp\samples\");
var env = builder.Environment.EnvironmentName; // null
var contentRoot = builder.Environment.ContentRootPath; // cwd
}
}
We expose an
IWebHostEnvironmentproperty on the builder (WebApplicationBuilder.Environment) in order to support conditional service registration (for e.g. base on the current environment). That property is currently incorrect when it comes to configuring the the host via UseEnvironment or UseContentRoot (or any other setting that affects the host configuration). We should decide how to fix it or what to do about this.PS: We also added the
IWebHostEnvironmentto allow various part of the ASP.NET Core stack that scan for assets based on application name to work. e.g. MVC https://github.com/dotnet/aspnetcore/blob/2e4274cb67c049055e321c18cc9e64562da52dcf/src/Mvc/Mvc.Core/src/DependencyInjection/MvcCoreServiceCollectionExtensions.cs#L81-L88)