本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.Add方法的具体用法?C# ConfigurationBuilder.Add怎么用?C# ConfigurationBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Extensions.Configuration.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.Add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Startup
public Startup(IApplicationEnvironment app, ILoggerFactory factory)
{
var jsonConfig = new JsonConfigurationProvider("config.json");
var environConfig = new EnvironmentVariablesConfigurationProvider();
var builder = new ConfigurationBuilder();
builder.Add(jsonConfig);
builder.Add(environConfig);
builder.SetBasePath(app.ApplicationBasePath);
Configuration = builder.Build();
Environment = app;
Factory = factory;
}
示例2: Configure
public void Configure(IApplicationBuilder app)
{
var builder = new ConfigurationBuilder();
builder.Add(new MemoryConfigurationProvider {
{"MySettings:RetryCount", "42"},
{"MySettings:DefaultAdBlock", "House"},
{"MySettings:AdBlock:House:ProductCode", "123"},
{"MySettings:AdBlock:House:Origin", "blob-456"},
{"MySettings:AdBlock:Contoso:ProductCode", "contoso2014"},
{"MySettings:AdBlock:Contoso:Origin", "sql-789"},
});
var config = builder.Build();
var mySettings = new MySettings();
mySettings.Read(config.GetSection("MySettings"));
app.Run(async ctx =>
{
ctx.Response.ContentType = "text/plain";
await ctx.Response.WriteAsync(string.Format("Retry Count {0}\r\n", mySettings.RetryCount));
await ctx.Response.WriteAsync(string.Format("Default Ad Block {0}\r\n", mySettings.DefaultAdBlock));
foreach (var adBlock in mySettings.AdBlocks.Values)
{
await ctx.Response.WriteAsync(string.Format(
"Ad Block {0} Origin {1} Product Code {2}\r\n",
adBlock.Name, adBlock.Origin, adBlock.ProductCode));
}
});
}
示例3: Load
public override void Load()
{
var builder = new ConfigurationBuilder();
builder.Add(new EnvironmentVariablesConfigurationProvider(VCAP_PREFIX));
var vcap = builder.Build();
Process(vcap);
}
示例4: Startup
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsetings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
builder.Add(new MemoryConfigurationProvider());
Configuration = builder.Build();
}
示例5: LoadJson
public static IConfiguration LoadJson(string configFile)
{
var config = new ConfigurationBuilder();
var source = new JsonConfigurationProvider("path", true);
using (var stream = typeof(EmbeddedConfiguration).GetTypeInfo().Assembly.GetManifestResourceStream("Autofac.Configuration.Test.Files." + configFile))
{
typeof(JsonConfigurationProvider).GetMethod("Load", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(source, new object[] { stream });
}
config.Add(source, false);
return config.Build();
}
示例6: Configure
public void Configure(IApplicationBuilder app)
{
var builder = new ConfigurationBuilder();
builder.Add(new MyConfigProvider());
var config = builder.Build();
app.Run(async ctx =>
{
ctx.Response.ContentType = "text/plain";
await DumpConfig(ctx.Response, config);
});
}
示例7: Start
private BackTelemetryChannel Start(string assemblyName)
{
var customConfig = new MemoryConfigurationProvider();
customConfig.Set("server.urls", this.BaseHost);
var configBuilder = new ConfigurationBuilder();
configBuilder.Add(customConfig);
var config = configBuilder.Build();
var engine = CreateBuilder(config)
.UseServer("Microsoft.AspNet.Server.WebListener")
.UseStartup(assemblyName)
.UseEnvironment("Production")
.Build();
this.hostingEngine = engine.Start();
return (BackTelemetryChannel)engine.ApplicationServices.GetService<ITelemetryChannel>();
}
示例8: Main
public void Main(string[] args)
{
var builder = new ConfigurationBuilder();
Console.WriteLine("Initial Config Providers: " + builder.Providers.Count());
var defaultSettings = new MemoryConfigurationProvider();
defaultSettings.Set("username", "Guest");
builder.Add(defaultSettings);
Console.WriteLine("Added Memory Provider. Providers: " + builder.Providers.Count());
builder.AddCommandLine(args);
Console.WriteLine("Added Command Line Provider. Providers: " + builder.Providers.Count());
var config = builder.Build();
string username = config["username"];
Console.WriteLine($"Hello, {username}!");
}
示例9: SetUpDefaultAssembly
private static IConfiguration SetUpDefaultAssembly(string assemblyName)
{
var source = new MemoryConfigurationProvider();
source.Add("defaultAssembly", assemblyName);
var config = new ConfigurationBuilder();
config.Add(source);
return config.Build();
}