本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.SetBasePath方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.SetBasePath方法的具体用法?C# ConfigurationBuilder.SetBasePath怎么用?C# ConfigurationBuilder.SetBasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Extensions.Configuration.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.SetBasePath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HalibutLimits
static HalibutLimits()
{
#if NET40
var settings = System.Configuration.ConfigurationManager.AppSettings;
var fields = typeof (HalibutLimits).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var field in fields)
{
var value = settings.Get("Halibut." + field.Name);
if (string.IsNullOrWhiteSpace(value)) continue;
var time = TimeSpan.Parse(value);
field.SetValue(null, time);
}
#else
// should be able to use Directory.GetCurrentDirectory()
// to get the working path, but the nunit test runner
// runs from another directory. Go with dll location for now.
var directory = Path.GetDirectoryName(new Uri(typeof(HalibutLimits).GetTypeInfo().Assembly.CodeBase).LocalPath);
var builder = new ConfigurationBuilder();
builder.SetBasePath(directory);
builder.AddJsonFile("appsettings.json", optional: true);
var halibutConfig = builder.Build();
var fields = typeof(HalibutLimits).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var field in fields)
{
var value = halibutConfig["Halibut:" + field.Name];
if (string.IsNullOrWhiteSpace(value)) continue;
var time = TimeSpan.Parse(value);
field.SetValue(null, time);
}
#endif
}
示例2: Startup
public Startup(IApplicationEnvironment env)
{
var builder = new ConfigurationBuilder();
builder.SetBasePath(env.ApplicationBasePath);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例3: ConfigureConfiguration
private static IConfiguration ConfigureConfiguration(IHostingEnvironment hostingEnvironment)
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.SetBasePath(hostingEnvironment.ContentRootPath);
configurationBuilder.AddJsonFile("config.json", optional: true);
configurationBuilder.AddEnvironmentVariables();
return configurationBuilder.Build();
}
示例4: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment app)
{
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.SetBasePath(app.ApplicationBasePath);
builder.AddJsonFile("appsettings.json");
IConfigurationRoot config = builder.Build();
AppSettings.ConnectionString = config.Get<string>
("Data:DefaultConnection:ConnectionString");
}
示例5: GetConfigurationRoot
private static IConfigurationRoot GetConfigurationRoot()
{
var builder = new ConfigurationBuilder();
var testFolder = new DirectoryInfo(Directory.GetCurrentDirectory()).FullName;
builder.SetBasePath(testFolder);
//use json file to configure settings. See http://docs.asp.net/en/latest/fundamentals/configuration.html for more detail on CongifurationBuilder
builder.AddJsonFile("appsettings.json");
var config = builder.Build();
return config;
}
示例6: GetConfiguration
/// <summary>
/// get IConfigurationRoot from rpclite.config.json
/// </summary>
/// <param name="basePath"></param>
/// <returns></returns>
public static IConfigurationRoot GetConfiguration(string basePath)
{
var configBuilder = new ConfigurationBuilder();
if (!string.IsNullOrWhiteSpace(basePath))
configBuilder.SetBasePath(basePath);
configBuilder
.AddJsonFile("rpclite.config.json", true);
var config = configBuilder.Build();
return config;
}
示例7: 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;
}
示例8: GetConfigurationRoot
private static IConfigurationRoot GetConfigurationRoot()
{
var builder = new ConfigurationBuilder();
//in-memory
SetConfigurationDefaults(builder);
//json
var dir = new DirectoryInfo(Directory.GetCurrentDirectory()).FullName;
var settingsFile = Path.Combine(dir, "appsettings.json");
builder.SetBasePath(dir);
if (File.Exists(settingsFile))
{
builder.AddJsonFile("appsettings.json");
}
var config = builder.Build();
return config;
}
示例9: Main
public static void Main()
{
// work with with a builder using multiple calls
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddJsonFile("appsettings.json");
var connectionStringConfig = builder.Build();
// chain calls together as a fluent API
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddEntityFrameworkConfig(options =>
options.UseSqlServer(connectionStringConfig.GetConnectionString("DefaultConnection"))
)
.Build();
Console.WriteLine("key1={0}", config["key1"]);
Console.WriteLine("key2={0}", config["key2"]);
Console.WriteLine("key3={0}", config["key3"]);
}
示例10: 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();
configurationBuilder.SetBasePath(hostingEnvironment.ContentRootPath);
// 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);
if (hostingEnvironment.IsDevelopment())
{
// 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.
// Only use this in Development, it is not intended for Production use. 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:
// [System.Environment]::GetEnvironmentVariable("[VARIABLE_NAME]", [System.EnvironmentVariableTarget]::Machine)
// Note: To set environment variables for the machine use the following command in PowerShell:
// [System.Environment]::SetEnvironmentVariable("[VARIABLE_NAME]", "[VARIABLE_VALUE]", [System.EnvironmentVariableTarget]::Machine)
// 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();
}
示例11: Main
public static void Main(string[] args)
{
var baseConfigBuilder = new ConfigurationBuilder();
baseConfigBuilder.SetBasePath(Directory.GetCurrentDirectory());
baseConfigBuilder.AddCommandLine(args);
baseConfigBuilder.AddEnvironmentVariables();
var configFile = baseConfigBuilder.Build()["config"];
if (string.IsNullOrEmpty(configFile))
{
Console.WriteLine("No Config File");
Console.WriteLine("Need Parameter \"--config path\"");
return;
}
baseConfigBuilder.AddJsonFile(configFile, true, true);
var baseConfig = baseConfigBuilder.Build();
var logConfigFile = baseConfig["Data:LogConfig"];
var notifyAppsConfigFile = baseConfig["Data:NotifyAppsConfig"];
var appChannelConfigFile = baseConfig["Data:AppChannelConfig"];
baseConfigBuilder
.AddJsonFile(logConfigFile, true, true)
.AddJsonFile(notifyAppsConfigFile, true, true)
.AddJsonFile(appChannelConfigFile, true, true);
Configuration = baseConfigBuilder.Build();
//Nlog
var nlogConfig = new NLog.Config.LoggingConfiguration();
BahamutCommon.LoggerLoaderHelper.LoadLoggerToLoggingConfig(nlogConfig, Configuration, "Logger:fileLoggers");
#if DEBUG
BahamutCommon.LoggerLoaderHelper.AddConsoleLoggerToLogginConfig(nlogConfig);
#endif
LogManager.Configuration = nlogConfig;
try
{
//CSServer
var server = new ChicagoServer();
Server = server;
server.UseNetConfig(new NetConfigReader());
server.UseServerConfig(new ServerConfigReader());
server.UseLogger(new FileLogger(Configuration["ServerLog"]));
#if DEBUG
server.UseLogger(ConsoleLogger.Instance);
#endif
server.UseMessageRoute(new JsonRouteFilter());
server.UseExtension(new BahamutUserValidationExtension());
server.UseExtension(new SharelinkerValidateExtension());
server.UseExtension(new BahamutAppValidateExtension());
//NotificationCenter Extension
var notificationExt = new NotificaionCenterExtension();
server.UseExtension(notificationExt);
server.UseExtension(new HeartBeatExtension());
server.StartServer();
#if DEBUG
DebugConsole();
#else
Thread.Sleep(Timeout.Infinite);
#endif
}
catch (Exception ex)
{
LogManager.GetLogger("Chicago").Fatal(ex);
throw;
}
}