ASP.NET 5 - Environment specific pipeline configuration


    // Example
    public class Startup
    {
        private readonly IHostingEnvironment _env;

        public Startup(IHostingEnvironment env)
        {
            _env = env;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            if (_env.IsEnvironment("Production"))
            {
                // read prod config
            }
            else
            {
                // read dev config
            }
        }

    .
    .
    .

   }

// Full example
    public class Startup
    {
        private readonly IHostingEnvironment _env;

        public Startup(IHostingEnvironment env)
        {
            _env = env;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            if (_env.IsEnvironment("Production"))
            {
                // read prod config
            }
            else if (_env.IsEnvironment("Staging"))
            {
                // read staging config
            }
            else
            {
                // read dev config
            }
        }

        public void ConfigureDevelopment(IApplicationBuilder builder, IHostingEnvironment env)
        {
            // Development configuration
            Configure(builder);
        }

        public void ConfigureStaging(IApplicationBuilder builder)
        {
            // Staging configuration
            Configure(builder);
        }

        public void ConfigureProduction(IApplicationBuilder builder)
        {
            // Production configuration
            Configure(builder);
        }

        public void Configure(IApplicationBuilder builder)
        {
            // Common
        }
    }
comments powered by Disqus