本文整理汇总了C#中Microsoft.Framework.Configuration.ConfigurationBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder类的具体用法?C# ConfigurationBuilder怎么用?C# ConfigurationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationBuilder类属于Microsoft.Framework.Configuration命名空间,在下文中一共展示了ConfigurationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UmbracoConfig
public UmbracoConfig(IApplicationEnvironment appEnv)
{
var cfg = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("umbraco.json");
_config = cfg.Build();
}
示例2: Startup
public Startup(IHostingEnvironment environment)
{
Configuration = new ConfigurationBuilder(".")
.AddJsonFile("config.json")
.AddEnvironmentVariables()
.Build();
}
示例3: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var configuration =
new ConfigurationBuilder(appEnv.ApplicationBasePath).AddJsonFile("config.json", false)
.AddEnvironmentVariables();
this.Configuration = configuration.Build();
}
示例4: Startup
public Startup(IApplicationEnvironment appEnv)
{
var configBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
configBuilder.AddUserSecrets();
configBuilder.AddEnvironmentVariables();
_configuration = configBuilder.Build();
}
示例5: 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();
}
}
示例6: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例7: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var path = _app.ApplicationBasePath;
var config = new ConfigurationBuilder()
.AddJsonFile($"{path}/config.json")
.Build();
string typeName = config.Get<string>("RepositoryType");
services.AddSingleton(typeof(IBoilerRepository), Type.GetType(typeName));
object repoInstance = Activator.CreateInstance(Type.GetType(typeName));
IBoilerRepository repo = repoInstance as IBoilerRepository;
services.AddInstance(typeof(IBoilerRepository), repo);
TimerAdapter timer = new TimerAdapter(0, 500);
BoilerStatusRepository db = new BoilerStatusRepository();
services.AddInstance(typeof(BoilerMonitor), new BoilerMonitor(repo, timer, db));
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
return services.BuildServiceProvider();
}
示例8: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
_basePath = appEnv.ApplicationBasePath;
Configuration = new ConfigurationBuilder()
.AddJsonFile(_basePath + "/App_Data/Development.json")
.Build();
}
示例9: Configure
public void Configure(IApplicationBuilder app)
{
ServiceProvider = app.ApplicationServices;
var applicationEnvironment = app.ApplicationServices.GetRequiredService<IApplicationEnvironment>();
var configurationFile = Path.Combine(applicationEnvironment.ApplicationBasePath, applicationEnvironment.ApplicationName) + ".json";
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile(configurationFile);
Configuration = configurationBuilder.Build();
ConfigureLogging(app);
// Add site logging.
app.Use(async (request, next) => {
var accessLine = "<Unknown>";
try {
var remoteAddress = "";
var connectionFeature = request.GetFeature<IHttpConnectionFeature>();
if (connectionFeature != null) {
remoteAddress = connectionFeature.RemoteIpAddress.ToString();
}
if (string.IsNullOrWhiteSpace(remoteAddress)) {
remoteAddress = request.Request.Headers["HTTP_X_FORWARDED_FOR"];
}
if (string.IsNullOrWhiteSpace(remoteAddress)) {
remoteAddress = request.Request.Headers["REMOTE_ADDR"];
}
accessLine = string.Format(
"{0} {1} {2} {3}{4}{5}",
remoteAddress,
request.Request.Method,
request.Request.Protocol,
request.Request.Path,
request.Request.QueryString.HasValue ? "?" : "",
request.Request.QueryString);
var isHtml = Path.GetExtension(request.Request.Path).Equals(".html");
if (isHtml) {
HtmlAccessLog.LogInformation(accessLine);
}
AccessLog.LogInformation(accessLine);
await next();
} catch (Exception e) {
var message = string.Format("Exception processing request {0}", accessLine);
ApplicationLog.LogError(message, e);
}
});
ConfigureFileServer(app);
}
示例10: Startup
public Startup(IApplicationEnvironment environment)
{
Configuration =
new ConfigurationBuilder(environment.ApplicationBasePath)
.AddJsonFile("config.json")
.Build();
}
示例11: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
configurationBuilder.AddEnvironmentVariables("BinaryMash.ReleaseManager:");
configurationBuilder.AddJsonFile("Config.json");
_configuration = configurationBuilder.Build();
}
示例12: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
//appEnv.
//env.EnvironmentName = "Development";
if (env.IsEnvironment("Development"))
{
// 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();
}
// this file name is ignored by gitignore
// so you can create it and use on your local dev machine
// remember last config source added wins if it has the same settings
builder.AddJsonFile("appsettings.local.overrides.json", optional: true);
// most common use of environment variables would be in azure hosting
// since it is added last anything in env vars would trump the same setting in previous config sources
// so no risk of messing up settings if deploying a new version to azure
builder.AddEnvironmentVariables();
Configuration = builder.Build();
//env.MapPath
}
示例13: Main
public void Main(string[] args)
{
var runtimeConfig = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var options = new Options();
runtimeConfig.Bind(options);
var queueConfig = new ConfigurationBuilder(".")
.AddJsonFile("queues.json")
.Build()
.GetSection(options.QueueType);
var services = BuildServiceProvider(options, queueConfig);
var logger = services.GetRequiredService<ILogger<Program>>();
var handlerFactory = services.GetRequiredService<IMessageHandlerFactory>();
var queueFactory = services.GetRequiredService<IMessageQueueFactory>();
var queue = queueFactory.Get(options.ListenTo);
queue.Listen(msg =>
{
var handler = handlerFactory.GetHandler(msg.Body.GetType());
handler.Handle(msg, queue);
});
}
示例14: 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;
}
示例15: CreateBuilder
private static IConfigurationBuilder CreateBuilder(IApplicationEnvironment appEnv)
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("Config.json")
.AddJsonFile("..\\Config.Bus.json");
return configurationBuilder;
}