本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder类的具体用法?C# ConfigurationBuilder怎么用?C# ConfigurationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationBuilder类属于Microsoft.Extensions.Configuration命名空间,在下文中一共展示了ConfigurationBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConfigureConfigServerClientSettingsOptions_WithDefaults
public void ConfigureConfigServerClientSettingsOptions_WithDefaults()
{
// Arrange
var services = new ServiceCollection().AddOptions();
var environment = new HostingEnvironment();
// Act and Assert
var builder = new ConfigurationBuilder().AddConfigServer(environment);
var config = builder.Build();
services.Configure<ConfigServerClientSettingsOptions>(config);
var service = services.BuildServiceProvider().GetService<IOptions<ConfigServerClientSettingsOptions>>();
Assert.NotNull(service);
var options = service.Value;
Assert.NotNull(options);
ConfigServerTestHelpers.VerifyDefaults(options.Settings);
Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, options.Enabled);
Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, options.FailFast);
Assert.Equal(ConfigServerClientSettings.DEFAULT_URI, options.Uri);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, options.Environment);
Assert.Equal(ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION, options.ValidateCertificates);
Assert.Null(options.Name);
Assert.Null(options.Label);
Assert.Null(options.Username);
Assert.Null(options.Password);
}
开发者ID:sdougherty,项目名称:Configuration,代码行数:27,代码来源:ConfigServerClientSettingsOptionsTest.cs
示例2: GetEnabledTenants
//<inheritdoc/>
public IEnumerable<Tenant> GetEnabledTenants()
{
var fileProvider = _hostingEnvironment.ContentRootFileProvider;
var tenantFolders = fileProvider
.GetDirectoryContents("tenants")
.Where(info => info.IsDirectory);
foreach (var tenantFolder in tenantFolders)
{
var tenantFileName = "tenant.json";
var tenantDirectoryPath = Path.Combine("tenants", tenantFolder.Name);
var tenantFilePath = Path.Combine(tenantDirectoryPath, tenantFileName);
var tenantFileInfo = fileProvider.GetFileInfo(tenantFilePath);
if (tenantFileInfo.Exists)
{
var builder = new ConfigurationBuilder();
builder.SetFileProvider(fileProvider);
builder.AddJsonFile(tenantFilePath);
var config = builder.Build();
var tenant = new Tenant
{
TenantId = tenantFolder.Name,
Configuration = config,
Identities = config.GetSection("Identities").GetChildren().Select(t => t.Value),
Extensions = config.GetSection("Extensions").GetChildren().Select(t => t.Value),
Path = tenantFolder.PhysicalPath
};
yield return tenant;
}
}
}
开发者ID:causer,项目名称:Itasu,代码行数:35,代码来源:TenantManager.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:284247028,项目名称:Brochard,代码行数:26,代码来源:ShellSettingsManager.cs
示例4: GatherParameters
private static DungeonParameters GatherParameters()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("AppSettings.json")
.AddEnvironmentVariables();
var configuration = builder.Build();
return new DungeonParameters
{
Width = configuration.GetValue<int>("Map:Width"),
Height = configuration.GetValue<int>("Map:Height"),
CellSparseFactor = configuration.GetValue<int>("Map:CellSparseFactor"),
DeadEndSparseFactor = configuration.GetValue<int>("Map:DeadEndSparseFactor"),
TwistFactor = configuration.GetValue<int>("Map:TwistFactor"),
RoomParameters = new RoomParameters
{
Count = configuration.GetValue<int>("Map:Room:Count"),
MinWidth = configuration.GetValue<int>("Map:Room:MinWidth"),
MaxWidth = configuration.GetValue<int>("Map:Room:MaxWidth"),
MinHeight = configuration.GetValue<int>("Map:Room:MinHeight"),
MaxHeight = configuration.GetValue<int>("Map:Room:MaxHeight")
}
};
}
开发者ID:CatSkald,项目名称:Roguelike,代码行数:25,代码来源:Program.cs
示例5: OnStart
protected override void OnStart(string[] args)
{
try
{
var configProvider = new MemoryConfigurationProvider();
configProvider.Add("server.urls", "http://localhost:5000");
var config = new ConfigurationBuilder()
.Add(configProvider)
.Build();
var builder = new WebHostBuilder(config);
builder.UseServer("Microsoft.AspNet.Server.Kestrel");
builder.UseServices(services => services.AddMvc());
builder.UseStartup(appBuilder =>
{
appBuilder.UseDefaultFiles();
appBuilder.UseStaticFiles();
appBuilder.UseMvc();
});
var hostingEngine = builder.Build();
_application = hostingEngine.Start();
}
catch (Exception ex)
{
Debug.WriteLine("error in OnStart: " + ex);
throw;
}
}
开发者ID:Roar1827,项目名称:aspnet-windows-service,代码行数:30,代码来源:Program.cs
示例6: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
//Setting up configuration builder
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddEnvironmentVariables();
if (!env.IsProduction())
{
builder.AddUserSecrets();
}
else
{
}
Configuration = builder.Build();
//Setting up configuration
if (!env.IsProduction())
{
var confConnectString = Configuration.GetSection("Data:DefaultConnection:ConnectionString");
confConnectString.Value = @"Server=(localdb)\mssqllocaldb;Database=GetHabitsAspNet5;Trusted_Connection=True;";
var identityConnection = Configuration.GetSection("Data:IdentityConnection:ConnectionString");
identityConnection.Value = @"Server=(localdb)\mssqllocaldb;Database=GetHabitsIdentity;Trusted_Connection=True;";
}
else
{
}
}
开发者ID:boyarincev,项目名称:GetHabitsAspNet5,代码行数:32,代码来源:Startup.cs
示例7: Startup
public Startup(
IHostingEnvironment env,
IApplicationEnvironment appEnv)
{
_env = env;
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
// standard config file
.AddJsonFile("config.json")
// environment specific config.<environment>.json file
.AddJsonFile($"config.{env.EnvironmentName}.json", true /* override if exists */)
// standard Windows environment variables
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// this one adds not using directive to keep it secret, only a dnx reference
// the focus is not on Secrets but on User, so these are User specific settings
// we can also make it available only for developers
builder.AddUserSecrets();
}
Configuration = builder.Build();
}
开发者ID:madrus,项目名称:mvaWebApp02,代码行数:26,代码来源:Startup.cs
示例8: Startup
public Startup(IHostingEnvironment hostingEnvironment, IApplicationEnvironment applicationEnvironment)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json")
.Build();
}
开发者ID:qbikez,项目名称:Odachi,代码行数:7,代码来源:Startup.cs
示例9: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder().AddEnvironmentVariables();
Configuration = builder.Build();
}
开发者ID:joekrie,项目名称:React.NET,代码行数:7,代码来源:Startup.cs
示例10: foreach
IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings()
{
var shellSettings = new List<ShellSettings>();
foreach (var tenant in _appDataFolder.ListDirectories(_optionsAccessor.Value.Location))
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);
}
var configurationContainer =
new ConfigurationBuilder()
.SetBasePath(_appDataFolder.RootPath)
.AddJsonFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "json")),
true)
.AddXmlFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "xml")),
true)
.AddYamlFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "txt")),
false);
var config = configurationContainer.Build();
var shellSetting = ShellSettingsSerializer.ParseSettings(config);
shellSettings.Add(shellSetting);
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
}
}
return shellSettings;
}
开发者ID:jimitndiaye,项目名称:Orchard2,代码行数:32,代码来源:ShellSettingsManager.cs
示例11: ProviderServices
public ProviderServices(IApplicationEnvironment env)
{
var configuration = new ConfigurationBuilder()
.BuildConfiguration(env);
_serviceProvider = new ServiceCollection()
.AddLogging()
.AddOptions()
.Configure<MailConfiguration>(configuration)
.Configure<TestOptions>(configuration)
.AddSingleton<TestConfiguration>()
.AddInstance(configuration)
.AddProceesProviderServices()
.AddTransient<IModifiedCodeTestsFinder, ModifiedCodeTestsFinder>()
.AddTransient<IDnxTestRunner, DnxTestRunner>()
.AddTransient<ITestRunner, TestRunner>()
.AddTransient<IMailServiceFactory, MailServiceFactory>()
.AddInstance(env)
.BuildServiceProvider();
_serviceProvider.GetService<ILoggerFactory>().AddConsole(LogLevel.Information);
}
开发者ID:jagasafari,项目名称:ContinuousIntegration,代码行数:27,代码来源:ProviderServices.cs
示例12: 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();
}
开发者ID:Pro-Coded,项目名称:Pro.MVCMagic,代码行数:42,代码来源:Startup.Configuration.cs
示例13: Startup
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new ConfigurationBuilder()
.AddJsonFile("config.json")
.Build();
}
开发者ID:RehanSaeed,项目名称:ApplicationInsights-aspnetcore,代码行数:7,代码来源:Startup.cs
示例14: Main
public static void Main(string[] args)
{
if (Debugger.IsAttached)
{
Environment.SetEnvironmentVariable(
"ASPNETCORE_ENVIRONMENT",
EnvironmentName.Development);
}
var config = new ConfigurationBuilder()
.AddJsonFile("hosting.json", optional: true)
.AddEnvironmentVariables("ASPNETCORE_")
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseConfiguration(config)
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
开发者ID:rfinochi,项目名称:confsamples,代码行数:25,代码来源:Program.cs
示例15: Main
public static void Main(string[] args)
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json");
var configuration = configBuilder.Build();
var hostBuilder = new WebHostBuilder();
// set urls and environment
hostBuilder
.UseUrls(configuration["urls"])
.UseEnvironment(configuration["environment"]);
// set other common things
hostBuilder
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
var host = hostBuilder.Build();
host.Run();
}
开发者ID:kosmakoff,项目名称:WebApiWithAuth,代码行数:26,代码来源:Program.cs
示例16: Startup
// ReSharper disable once UnusedParameter.Local
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("config.json")
.AddEnvironmentVariables("Dorothy:");
Configuration = builder.Build();
}
开发者ID:saxx,项目名称:Project-Dorothy,代码行数:8,代码来源:Startup.cs
示例17: Run
public void Run()
{
try
{
Console.WriteLine("Reading Configuration");
var builder = new ConfigurationBuilder()
.SetBasePath(PlatformServices.Default.Application.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
_config = builder.Build();
_ctx = new OldWilderContext(_config);
_newCtx = new WilderContext(_config);
_repo = new WilderRepository(_config, _newCtx);
Console.WriteLine("Migrating Stories");
MigrateStories();
//TODO More migration
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadKey();
}
}
开发者ID:fransen,项目名称:WilderBlog,代码行数:27,代码来源:SiteMigration.cs
示例18: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
Configuration = new ConfigurationBuilder()
.AddJsonFile(ConfigFilename)
.AddEnvironmentVariables()
.Build();
}
开发者ID:PavelRudko,项目名称:BodyHelper,代码行数:7,代码来源:Startup.cs
示例19: Startup
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:7,代码来源:Startup.cs
示例20: RegisterAddresses_Success
public async Task RegisterAddresses_Success(string addressInput, string[] testUrls)
{
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{ "server.urls", addressInput }
})
.Build();
var applicationBuilder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(ConfigureEchoAddress);
using (var app = applicationBuilder.Build().Start())
{
using (var client = new HttpClient())
{
foreach (var testUrl in testUrls)
{
var responseText = await client.GetStringAsync(testUrl);
Assert.Equal(testUrl, responseText);
}
}
}
}
开发者ID:leloulight,项目名称:KestrelHttpServer,代码行数:26,代码来源:AddressRegistrationTests.cs
注:本文中的Microsoft.Extensions.Configuration.ConfigurationBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论