Skip to content

Settings that affect IWebHostEnvironment and IHostEnvironment do not work #19

Description

@davidfowl

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions