当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.Add方法代码示例

本文整理汇总了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;
        }
开发者ID:inkysigma,项目名称:InkySigma,代码行数:15,代码来源:Startup.cs

示例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));                
            }
        });
    }
开发者ID:leloulight,项目名称:Entropy,代码行数:30,代码来源:Startup.cs

示例3: Load

 public override void Load()
 {
     var builder = new ConfigurationBuilder();
     builder.Add(new EnvironmentVariablesConfigurationProvider(VCAP_PREFIX));
     var vcap = builder.Build();
     Process(vcap);
 }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:7,代码来源:CloudFoundryConfigurationProvider.cs

示例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();
		}
开发者ID:felixshu,项目名称:Practice,代码行数:11,代码来源:Startup.cs

示例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();
 }
开发者ID:MyLobin,项目名称:Autofac.Configuration,代码行数:11,代码来源:EmbeddedConfiguration.cs

示例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);
        });
    }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-Entropy-aspnet,代码行数:12,代码来源:Startup.cs

示例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>();
        }
开发者ID:fjsnogueira,项目名称:ApplicationInsights-aspnetcore,代码行数:17,代码来源:InProcessServer.cs

示例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}!");
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:18,代码来源:Program.cs

示例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();
 }
开发者ID:MyLobin,项目名称:Autofac.Configuration,代码行数:8,代码来源:ConfigurationExtensionsFixture.cs


注:本文中的Microsoft.Extensions.Configuration.ConfigurationBuilder.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。