How to get the Development/Staging/production Hosting Environment in ConfigureServices

前端 未结 12 1850
时光取名叫无心
时光取名叫无心 2020-12-04 15:51

How do I get the Development/Staging/production Hosting Environment in the ConfigureServices method in Startup?

public void ConfigureServices(IS         


        
12条回答
  •  攒了一身酷
    2020-12-04 16:51

    per the docs

    Configure and ConfigureServices support environment specific versions of the form Configure{EnvironmentName} and Configure{EnvironmentName}Services:

    You can do something like this...

    public void ConfigureProductionServices(IServiceCollection services)
    {
        ConfigureCommonServices(services);
    
        //Services only for production
        services.Configure();
    }
    
    public void ConfigureDevelopmentServices(IServiceCollection services)
    {
        ConfigureCommonServices(services);
    
        //Services only for development
        services.Configure();
    }
    
    public void ConfigureStagingServices(IServiceCollection services)
    {
        ConfigureCommonServices(services);
    
        //Services only for staging
        services.Configure();
    }
    
    private void ConfigureCommonServices(IServiceCollection services)
    {
        //Services common to each environment
    }
    

提交回复
热议问题