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


C# ConfigurationBuilder.Build方法代码示例

本文整理汇总了C#中Microsoft.Framework.Configuration.ConfigurationBuilder.Build方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.Build方法的具体用法?C# ConfigurationBuilder.Build怎么用?C# ConfigurationBuilder.Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Framework.Configuration.ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.Build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddCaching();
            services.AddSession();

            services.AddMvc();
            services.AddSingleton<PassThroughAttribute>();
            services.AddSingleton<UserNameService>();
            services.AddTransient<ITestService, TestService>();

            services.ConfigureMvc(options =>
            {
                options.Filters.Add(typeof(PassThroughAttribute), order: 17);
                options.AddXmlDataContractSerializerFormatter();
                options.Filters.Add(new FormatFilterAttribute());
            });

            services.AddMvcLocalization(LanguageViewLocationExpanderOption.SubFolder);

#if DNX451
            // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine
            // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment.
            // Functional tests update that service but not in the static provider.
            var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
            var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json");

            // Set up configuration sources.
            var configBuilder = new ConfigurationBuilder()
                .AddJsonFile(configurationPath)
                .AddEnvironmentVariables();

            var configuration = configBuilder.Build();

            string diSystem;
            if (configuration.TryGet("DependencyInjection", out diSystem) &&
                diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase))
            {
                _autoFac = true;

                // Create the autofac container
                var builder = new ContainerBuilder();

                // Create the container and use the default application services as a fallback
                AutofacRegistration.Populate(
                    builder,
                    services);

                builder.RegisterModule<MonitoringModule>();

                var container = builder.Build();

                return container.Resolve<IServiceProvider>();
            }
            else
#endif
            {
                return services.BuildServiceProvider();
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:59,代码来源:Startup.cs

示例2: Main

        public void Main(string[] args)
        {
            var builder = new ConfigurationBuilder(".");
            builder.AddJsonFile("appsettings.json");
            builder.AddEnvironmentVariables();
            var config = builder.Build();

            builder.AddEntityFramework(options => options.UseSqlServer(config["Data:DefaultConnection:ConnectionString"]));
            config = builder.Build();

            Console.WriteLine("key1={0}", config.Get("key1"));
            Console.WriteLine("key2={0}", config.Get("key2"));
            Console.WriteLine("key3={0}", config.Get("key3"));

        }
开发者ID:alibaba0012013,项目名称:aspnet-docs,代码行数:15,代码来源:Program.cs

示例3: foreach

        IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var shellSettings = new List<ShellSettings>();

            foreach (var tenant in _appDataFolder.ListDirectories("Sites")) {
                _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);

                var configurationContainer =
                    new ConfigurationBuilder()
                        .AddJsonFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "json")),
                            true)
                        .AddXmlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "xml")),
                            true)
                        .AddYamlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "txt")),
                            false);

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings(config);
                shellSettings.Add(shellSetting);

                _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
            }

            return shellSettings;
        }
开发者ID:vebin,项目名称:Brochard,代码行数:26,代码来源:ShellSettingsManager.cs

示例4: Main

        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationProvider("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];
            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(config["Data:AzureWebJobsStorage:ConnectionString"]);
            var host = new JobHost(jobHostConfig);
            var methodInfo = typeof(Functions).GetMethods().First();

            host.Call(methodInfo);
            return 0;
        }
开发者ID:dpiessens,项目名称:PartsUnlimited,代码行数:26,代码来源:Program.cs

示例5: Functional

        public Functional()
        {
            var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
            Debug.Assert(appEnv != null, "appEnv != null");
            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
            builder.AddJsonFile("config.json");
            builder.AddJsonFile("config.private.json", true);
            var configuration = builder.Build();

            var uri = new Uri(configuration["ServerCredentialUri"]);
            var username = configuration["ServerCredentialUsername"];
            var password = configuration["ServerCredentialPassword"];

            _serverCredential = new ServerCredential(uri, username, password);

            _freeMusicTorrentFile =
                new HttpClient().GetByteArrayAsync(
                    new Uri("http://bt.etree.org/download.php/582271/hottuna2015-09-11.flac16.torrent")).Result;
            _freeMusicTorrentHash = "9ecc7229ff971d27552dd399509e188847dbbbf1";

            // Make sure there is no torrents before executing the tests
            var api = new Api(_serverCredential);
            var torrents = api.GetTorrents().Result;
            if (torrents.Any())
            {
                var result = api.Perform(Action.Removedata, torrents.Select(t => t.InfoHash)).Result;
                Assert.True(result);
            }
        }
开发者ID:rbarbe,项目名称:HadoukenApi,代码行数:29,代码来源:Functional.cs

示例6: Main

        public void Main(string[] args)
        {
            _serviceCollection.AddDaniel15();
            var builder = new ConfigurationBuilder(_appEnv.ApplicationBasePath)
                // This is extremely ugly, but the paths differ in dev vs in prod.
                // Need to figure out a nicer way of doing this.
                .AddJsonFile("..\\Daniel15.Web\\config.json", optional: true)
                .AddJsonFile("../../../../../../site/approot/packages/Daniel15.Web/1.0.0/root/config.Production.json", optional: true)
                .AddEnvironmentVariables();
            _serviceCollection.AddDaniel15Config(builder.Build());
            _serviceCollection.AddOptions();
            _serviceProvider = _serviceCollection.BuildServiceProvider();

            var operation = args[0];
            switch (operation)
            {
                case "-disqus":
                    _serviceProvider.GetRequiredService<IDisqusComments>().Sync();
                    break;

                case "-social":
                    ActivatorUtilities.CreateInstance<SocialShareUpdater>(_serviceProvider).Run();
                    break;

                case "-projects":
                    ActivatorUtilities.CreateInstance<ProjectUpdater>(_serviceProvider).Run();
                    break;

                default:
                    throw new Exception("Invalid operation '" + operation + "'");
            }
        }
开发者ID:xb11,项目名称:Website,代码行数:32,代码来源:CronRunner.cs

示例7: Startup

 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
     configurationBuilder.AddEnvironmentVariables("BinaryMash.ReleaseManager:");
     configurationBuilder.AddJsonFile("Config.json");
     _configuration = configurationBuilder.Build();
 }
开发者ID:binarymash,项目名称:ReleaseManager2,代码行数:7,代码来源:Startup.cs

示例8: Startup

 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var configuration =
         new ConfigurationBuilder(appEnv.ApplicationBasePath).AddJsonFile("config.json", false)
             .AddEnvironmentVariables();
     this.Configuration = configuration.Build();
 }
开发者ID:LukaszSzulc,项目名称:TGD.NET,代码行数:7,代码来源:Startup.cs

示例9: Startup

 public Startup(IApplicationEnvironment appEnv)
 {
     var configBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
     configBuilder.AddUserSecrets();
     configBuilder.AddEnvironmentVariables();
     _configuration = configBuilder.Build();
 }
开发者ID:glennc,项目名称:GHUtils,代码行数:7,代码来源:Startup.cs

示例10: UmbracoConfig

 public UmbracoConfig(IApplicationEnvironment appEnv)
 {
     var cfg = new ConfigurationBuilder()
         .SetBasePath(appEnv.ApplicationBasePath)
         .AddJsonFile("umbraco.json");
     _config = cfg.Build();
 }
开发者ID:ryanmcdonough,项目名称:Umbraco9,代码行数:7,代码来源:UmbracoConfig.cs

示例11: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            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();

                // todo: use Configuration with config.json instead of hardcoded URLs
                AppSettings["WeatherApiDomain"] = "http://localhost:60583";
            }
            else
            {
                AppSettings["WeatherApiDomain"] = "http://nws-wapi-staging.azurewebsites.net:80";
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:johnsoaa,项目名称:weather-ui,代码行数:25,代码来源:Startup.cs

示例12: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.WithMachineName()
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .WriteTo.Seq("http://localhost:5341")
                .CreateLogger();

            Log.Information("Starting up");

            Metrics.Collector = new CollectorConfiguration()
                .Batch.AtInterval(TimeSpan.FromSeconds(5))
                .Tag.With("host", Environment.GetEnvironmentVariable("COMPUTERNAME"))
                .WriteTo.InfluxDB("http://192.168.99.100:8086", "data")
                .CreateCollector();

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:nblumhardt,项目名称:Bagels,代码行数:25,代码来源:Startup.cs

示例13: Startup

        public Startup(IApplicationEnvironment env)
        {
            var builder = new ConfigurationBuilder(env.ApplicationBasePath)
               .AddJsonFile("config.json");

            config = builder.Build();
        }
开发者ID:Initlipton,项目名称:PlanetDatabase,代码行数:7,代码来源:Startup.cs

示例14: Main

 public void Main(string[] args)
 {
     // Setup configuration sources.
     // The order in which Configuration is built
     // is important
     var builder = new ConfigurationBuilder(Options.ApplicationBaseDirectory)
         .AddJsonFile("config.json")
         .AddEnvironmentVariables()
         .AddUserSecrets()
         .AddCommandLine(args);
     Configuration = builder.Build();
     // Instantiate a new Twilio Rest Client
     var client = new TwilioRestClient(
       Configuration.Get("AccountSid"),
       Configuration.Get("AuthToken")
     );
     // Select all calls from my account
     var calls = client.ListCalls(new CallListRequest());
     // Check for any exceptions
     if (calls.RestException != null)
     {
         throw new FormatException(calls.RestException.Message);
     }
     // Loop through them and show information
     foreach (var call in calls.Calls)
     {
         var callDetails = $"From: {call.From}, Day: {call.DateCreated}, Duration: {call.Duration}s";
         WriteLine(callDetails);
     }
     ReadLine();
 }
开发者ID:ZhangYueqiu,项目名称:asp5-mvc6-examples,代码行数:31,代码来源:Program.cs

示例15: ActivityApiControllerTest

        public ActivityApiControllerTest()
        {
            if (_serviceProvider == null)
            {
                var services = new ServiceCollection();

                // Add Configuration to the Container
                var builder = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddEnvironmentVariables();
                IConfiguration configuration = builder.Build();
                services.AddSingleton(x => configuration);

                // Add EF (Full DB, not In-Memory)
                services.AddEntityFramework()
                    .AddInMemoryDatabase()
                    .AddDbContext<AllReadyContext>(options => options.UseInMemoryDatabase());

                // Setup hosting environment
                IHostingEnvironment hostingEnvironment = new HostingEnvironment();
                hostingEnvironment.EnvironmentName = "Development";
                services.AddSingleton(x => hostingEnvironment);
                _serviceProvider = services.BuildServiceProvider();
            }
        }
开发者ID:ResaWildermuth,项目名称:allReady,代码行数:25,代码来源:ActivityApiControllerTests.cs


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