本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.AddEnvironmentVariables方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddEnvironmentVariables方法的具体用法?C# ConfigurationBuilder.AddEnvironmentVariables怎么用?C# ConfigurationBuilder.AddEnvironmentVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Extensions.Configuration.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.AddEnvironmentVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Startup
public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
{
InitializeLogging(loggerFactory);
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json");
if (env.IsDevelopment())
{
// This reads the configuration keys from the secret store.
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
// Uncomment the block of code below if you want to load secrets from KeyVault
// It is recommended to use certs for all authentication when using KeyVault
//#if NET451
// var config = builder.Build();
// builder.AddKeyVaultSecrets(config["AzureAd:ClientId"],
// config["KeyVault:Name"],
// config["AzureAd:Asymmetric:CertificateThumbprint"],
// Convert.ToBoolean(config["AzureAd:Asymmetric:ValidationRequired"]),
// loggerFactory);
//#endif
Configuration = builder.Build();
}
示例2: ConfigureConfiguration
/// <summary>
/// Creates and configures the application configuration, where key value pair settings are stored. See
/// http://docs.asp.net/en/latest/fundamentals/configuration.html
/// http://weblog.west-wind.com/posts/2015/Jun/03/Strongly-typed-AppSettings-Configuration-in-ASPNET-5
/// </summary>
/// <param name="hostingEnvironment">The environment the application is running under. This can be Development,
/// Staging or Production by default.</param>
/// <returns>A collection of key value pair settings.</returns>
private static IConfiguration ConfigureConfiguration(IHostingEnvironment hostingEnvironment)
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
// Add configuration from the config.json file.
configurationBuilder.AddJsonFile("config.json");
// Add configuration from an optional config.development.json, config.staging.json or
// config.production.json file, depending on the environment. These settings override the ones in the
// config.json file.
configurationBuilder.AddJsonFile($"config.{hostingEnvironment.EnvironmentName}.json", optional: true);
// This reads the configuration keys from the secret store. This allows you to store connection strings
// and other sensitive settings, so you don't have to check them into your source control provider. See
// http://go.microsoft.com/fwlink/?LinkID=532709 and
// http://docs.asp.net/en/latest/security/app-secrets.html
configurationBuilder.AddUserSecrets();
// Add configuration specific to the Development, Staging or Production environments. This config can
// be stored on the machine being deployed to or if you are using Azure, in the cloud. These settings
// override the ones in all of the above config files.
// Note: To set environment variables for debugging navigate to:
// Project Properties -> Debug Tab -> Environment Variables
// Note: To get environment variables for the machine use the following command in PowerShell:
// $env:[VARIABLE_NAME]
// Note: To set environment variables for the machine use the following command in PowerShell:
// $env:[VARIABLE_NAME]="[VARIABLE_VALUE]"
// Note: Environment variables use a colon separator e.g. You can override the site title by creating a
// variable named AppSettings:SiteTitle. See
// http://docs.asp.net/en/latest/security/app-secrets.html
configurationBuilder.AddEnvironmentVariables();
return configurationBuilder.Build();
}
示例3: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Configuration
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
builder.AddEnvironmentVariables();
builder.Build();
// Logging
loggerFactory.AddDebug(minLevel: LogLevel.Verbose);
// Using different environments
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { }
// Middlewares
app.UseDeveloperExceptionPage();
app.UseRuntimeInfoPage(); // default path is /runtimeinfo
app.UseDefaultFiles();
app.UseStaticFiles();
// Web sockets
app.Map("/Managed", (appBuilder) => WebSocketsHelper.Configure(appBuilder, loggerFactory));
// IIS
app.UseIISPlatformHandler();
}
示例4: Startup
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
#if DEBUG
URLS.Api_url = "http://localhost:58517/";
URLS.Html_url = "http://localhost:7079/oauth.html";
URLS.Idt_url = "http://localhost:58058/";
URLS.Mvc_url = "http://localhost:7079/signin-oidc";
#endif
#if RELEASE
URLS.Api_url = "http://it4govwebapi.azurewebsites.net/";
URLS.Html_url = "http://it4govwebapp.azurewebsites.net/oauth.html";
URLS.Idt_url = "http://it4govidentityserver.azurewebsites.net";
URLS.Mvc_url = "http://it4govwebapp.azurewebsites.net/signin-oidc";
#endif
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build().ReloadOnChanged("appsettings.json");
}
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// add the config file which stores the connection string
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
builder.AddEnvironmentVariables();
Configuration = builder.Build();
// add entity framework using the config connection string
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// add identity: note the AddOpenIddictCore call
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddOpenIddictCore<Application>(config => config.UseEntityFramework());
// assuming you have an api...
services.AddMvc();
// for seeding the database with the demo user details
services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>();
}
示例6: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
_hostingEnvironment = env;
var RollingPath = Path.Combine(appEnvironment.ApplicationBasePath, "logs/myapp-{Date}.txt");
Log.Logger = new LoggerConfiguration()
.WriteTo.RollingFile(RollingPath)
.CreateLogger();
Log.Information("Ah, there you are!");
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings-filters.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
// Initialize the global configuration static
GlobalConfigurationRoot.Configuration = Configuration;
}
示例7: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsEnvironment("Development"))
{
// This reads the configuration keys from the secret store.
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
// this file name is ignored by gitignore
// so you can create it and use on your local dev machine
// remember last config source added wins if it has the same settings
builder.AddJsonFile("appsettings.local.overrides.json", optional: true);
// most common use of environment variables would be in azure hosting
// since it is added last anything in env vars would trump the same setting in previous config sources
// so no risk of messing up settings if deploying a new version to azure
builder.AddEnvironmentVariables();
Configuration = builder.Build();
//env.MapPath
appBasePath = appEnv.ApplicationBasePath;
}
示例8: Startup
public Startup()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例9: Register
public void Register(IServiceCollection serviceCollection)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
builder.AddEnvironmentVariables();
serviceCollection.AddInstance<IConfiguration>(builder.Build());
}
示例10: Startup
public Startup(IApplicationEnvironment env)
{
var builder = new ConfigurationBuilder();
builder.SetBasePath(env.ApplicationBasePath);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例11: Startup
public Startup(IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json");
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例12: Startup
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder();
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例13: Startup
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
builder.AddEnvironmentVariables();
Configuration = builder.Build().ReloadOnChanged("appsettings.json");
}
示例14: Startup
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例15: Startup
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}