本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration.AddEnvironmentVariables方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.AddEnvironmentVariables方法的具体用法?C# Configuration.AddEnvironmentVariables怎么用?C# Configuration.AddEnvironmentVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Framework.ConfigurationModel.Configuration
的用法示例。
在下文中一共展示了Configuration.AddEnvironmentVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
/// <summary>
/// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
/// </summary>
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
/* TODO: #10
services.AddCaching();
services.AddSession();
services.ConfigureSession(o =>
{
o.IdleTimeout = TimeSpan.FromMinutes(5);
});*/
services.AddTransient<WopiAuthorizationAttribute>();
// Autofac resolution
var builder = new ContainerBuilder();
// Configuration
Configuration configuration = new Configuration();
configuration.AddEnvironmentVariables();
builder.RegisterInstance(configuration).As<IConfiguration>().SingleInstance();
// File provider implementation
var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
var assembly = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));
builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();
builder.Populate(services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
示例2: Configure
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");
config.AddJsonFile("config.dev.json", true);
config.AddUserSecrets();
var password = config.Get("password");
if (config.Get<bool>("RecreateDatabase"))
{
var context = app.ApplicationServices.GetService<Models.BlogDataContext>();
context.Database.EnsureDeleted();
System.Threading.Thread.Sleep(2000);
context.Database.EnsureCreated();
}
if (config.Get<bool>("debug"))
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Home}/{action=Index}/{id?}"));
app.UseFileServer();
}
示例3: Configure
public void Configure(IBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
// Set up application services
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc();
});
// Enable Browser Link support
app.UseBrowserLink();
// Add static files to the request pipeline
app.UseStaticFiles();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例4: Startup
public Startup(
IHostingEnvironment hostingEnvironment,
ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Startup>();
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
var loggingConfiguration = configuration.GetSubKey("Logging");
var serilog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithMachineName()
.Enrich.WithProcessId()
.Enrich.WithThreadId();
if (string.Equals(hostingEnvironment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
serilog.WriteTo.ColoredConsole();
}
string elasticSearchConnectionString;
if (loggingConfiguration.TryGet("ElasticSearch:Server", out elasticSearchConnectionString))
{
serilog.WriteTo.ElasticSearch(node: new Uri(elasticSearchConnectionString));
}
loggerFactory.AddSerilog(serilog);
}
示例5: Startup
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
示例6: Configure
public void Configure(IBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
app.UseOwin();
// Set up application services
app.UseServices(services =>
{ // Add MVC services to the services container
services.AddMvc();
services.SetupOptions<MvcOptions>(options => {
System.Diagnostics.Debug.WriteLine(options.OutputFormatters.Select(item => item.GetType().Name));
options.OutputFormatters.RemoveAt(0);
});
});
// Add static files to the request pipeline
app.UseStaticFiles();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
//routes.MapRoute(
// name: "default",
// template: "{controller}/{action}/{id?}",
// defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "api",
template: "{controller}/{id?}");
});
}
示例7: Startup
public Startup(IHostingEnvironment env)
{
var configuration = new Configuration()
.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
示例8: Configure
public void Configure(IApplicationBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
// Set up application services
app.UseServices(services =>
{
services.AddAssembly(this);
// Add EF services to the services container
services.AddEntityFramework()
.AddSqlServer();
// Configure DbContext
services.SetupOptions<DbContextOptions>(options =>
{
options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
});
//// Add Identity services to the services container
//services.AddIdentitySqlServer<ApplicationDbContext, ApplicationUser>()
// .AddAuthentication();
// Add MVC services to the services container
services.AddMvc();
services.AddTransient(typeof(IService1), typeof(Service1));
});
// Enable Browser Link support
//app.UseBrowserLink();
// Add static files to the request pipeline
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType,
LoginPath = new PathString("/Account/Login"),
});
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "api",
template: "{controller}/{id?}");
});
}
示例9: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new Configuration()
.AddJsonFile("config.json");
builder.AddEnvironmentVariables();
Configuration = builder;
}
示例10: ConfigSetup
public ConfigSetup()
{
// Make individual calls to AddXXX extension methods
var config = new Configuration();
config.AddJsonFile("config.json");
config.AddEnvironmentVariables();
// Fluent configuration
var configFluent = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
示例11: Configure
public void Configure(IBuilder app)
{
// Enable Browser Link support
app.UseBrowserLink();
// Setup configuration sources
var configuration = new Configuration();
//configuration.AddIniFile("config.ini");
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
//app.Run(async context =>
//{
// await context.Response.WriteAsync(configuration.Get("Data:Configuration"));
//});
app.Run(async context =>
{
var asm = Assembly.Load(new AssemblyName("klr.host"));
var assemblyVersion = asm.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
await context.Response.WriteAsync(assemblyVersion.InformationalVersion);
});
// Set up application services
app.UseServices(services =>
{
// Add EF services to the services container
services.AddEntityFramework().AddInMemoryStore();
services.AddScoped<PersonContext>();
// Add MVC services to the services container
services.AddMvc();
});
// Add static files to the request pipeline
app.UseStaticFiles();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "api",
template: "{controller}/{id?}");
});
}
示例12: Startup
public Startup(IHostingEnvironment env)
{
System.Console.WriteLine(env.EnvironmentName);
// Setup configuration sources.
var configuration = new Configuration()
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
示例13: Startup
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
var configuration = new Configuration()
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsEnvironment("Development"))
{
configuration.AddUserSecrets();
}
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
示例14: Startup
public Startup(IHostingEnvironment env) {
// Setup configuration sources.
var configuration = new Configuration()
.AddJsonFile("config.json")
.AddJsonFile($"config.{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
configuration.AddUserSecrets();
}
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
示例15: Main
public void Main(string[] args)
{
var config = new Configuration();
if (File.Exists(HostingIniFile))
{
config.AddIniFile(HostingIniFile);
}
config.AddEnvironmentVariables();
config.AddCommandLine(args);
var context = new HostingContext()
{
Configuration = config,
ServerFactoryLocation = config.Get("server"),
ApplicationName = config.Get("app")
};
var engine = new HostingEngine(_serviceProvider);
var serverShutdown = engine.Start(context);
var loggerFactory = context.ApplicationServices.GetRequiredService<ILoggerFactory>();
var appShutdownService = context.ApplicationServices.GetRequiredService<IApplicationShutdown>();
var shutdownHandle = new ManualResetEvent(false);
appShutdownService.ShutdownRequested.Register(() =>
{
try
{
serverShutdown.Dispose();
}
catch (Exception ex)
{
var logger = loggerFactory.CreateLogger<Program>();
logger.LogError("Dispose threw an exception.", ex);
}
shutdownHandle.Set();
});
var ignored = Task.Run(() =>
{
Console.WriteLine("Started");
Console.ReadLine();
appShutdownService.RequestShutdown();
});
shutdownHandle.WaitOne();
}