本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration类的典型用法代码示例。如果您正苦于以下问题:C# Configuration类的具体用法?C# Configuration怎么用?C# Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于Microsoft.Framework.ConfigurationModel命名空间,在下文中一共展示了Configuration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
});
#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 configuration = new Configuration()
.AddJsonFile(configurationPath)
.AddEnvironmentVariables();
string diSystem;
if (configuration.TryGet("DependencyInjection", out diSystem) &&
diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase))
{
_autoFac = true;
services.ConfigureRazorViewEngine(options =>
{
var expander = new LanguageViewLocationExpander(
context => context.HttpContext.Request.Query["language"]);
options.ViewLocationExpanders.Insert(0, expander);
});
// 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:AndersBillLinden,项目名称:Mvc,代码行数:60,代码来源:Startup.cs
示例2: RegisterConfiguration
public static IConfigurationSourceRoot RegisterConfiguration([NotNull] this Startup startup, [NotNull] string toolsDirectory, [NotNull] string projectDirectory, ConfigurationOptions options)
{
var configuration = new Microsoft.Framework.ConfigurationModel.Configuration();
configuration.Add(new MemoryConfigurationSource());
configuration.Set(Constants.Configuration.ToolsDirectory, toolsDirectory);
configuration.Set(Constants.Configuration.ProjectDirectory, projectDirectory);
configuration.Set(Constants.Configuration.SystemConfigFileName, "scconfig.json");
var configurationService = new ConfigurationService(configuration);
if ((options & ConfigurationOptions.DoNotLoadConfig) != ConfigurationOptions.DoNotLoadConfig)
{
try
{
configurationService.Load(options);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return null;
}
}
return configuration;
}
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:27,代码来源:StartupExtensions.cs
示例3: Configure
public void Configure(IBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
app.UseOwin();
// Set up application services
app.UseServices(services =>
{ // Add MVC services to the services container
services.AddMvc();
services.SetupOptions<MvcOptions>(options => {
System.Diagnostics.Debug.WriteLine(options.OutputFormatters.Select(item => item.GetType().Name));
options.OutputFormatters.RemoveAt(0);
});
});
// Add static files to the request pipeline
app.UseStaticFiles();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
//routes.MapRoute(
// name: "default",
// template: "{controller}/{action}/{id?}",
// defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "api",
template: "{controller}/{id?}");
});
}
开发者ID:niklaslundberg,项目名称:VisualStudio-UF,代码行数:35,代码来源:Startup.cs
示例4: CanGetSubKey
public void CanGetSubKey()
{
// Arrange
var dic1 = new Dictionary<string, string>()
{
{"Data:DB1:Connection1", "MemVal1"},
{"Data:DB1:Connection2", "MemVal2"}
};
var dic2 = new Dictionary<string, string>()
{
{"DataSource:DB2:Connection", "MemVal3"}
};
var dic3 = new Dictionary<string, string>()
{
{"Data", "MemVal4"}
};
var memConfigSrc1 = new MemoryConfigurationSource(dic1);
var memConfigSrc2 = new MemoryConfigurationSource(dic2);
var memConfigSrc3 = new MemoryConfigurationSource(dic3);
var config = new Configuration();
config.AddLoadedSource(memConfigSrc1);
config.AddLoadedSource(memConfigSrc2);
config.AddLoadedSource(memConfigSrc3);
string memVal1, memVal2, memVal3, memVal4, memVal5;
bool memRet1, memRet2, memRet3, memRet4, memRet5;
// Act
var configFocus = config.GetSubKey("Data");
memRet1 = configFocus.TryGet("DB1:Connection1", out memVal1);
memRet2 = configFocus.TryGet("DB1:Connection2", out memVal2);
memRet3 = configFocus.TryGet("DB2:Connection", out memVal3);
memRet4 = configFocus.TryGet("Source:DB2:Connection", out memVal4);
memRet5 = configFocus.TryGet(null, out memVal5);
// Assert
Assert.True(memRet1);
Assert.True(memRet2);
Assert.False(memRet3);
Assert.False(memRet4);
Assert.True(memRet5);
Assert.Equal("MemVal1", memVal1);
Assert.Equal("MemVal2", memVal2);
Assert.Equal("MemVal4", memVal5);
Assert.Equal("MemVal1", configFocus.Get("DB1:Connection1"));
Assert.Equal("MemVal2", configFocus.Get("DB1:Connection2"));
Assert.Null(configFocus.Get("DB2:Connection"));
Assert.Null(configFocus.Get("Source:DB2:Connection"));
Assert.Equal("MemVal4", configFocus.Get(null));
Assert.Equal("MemVal1", configFocus["DB1:Connection1"]);
Assert.Equal("MemVal2", configFocus["DB1:Connection2"]);
Assert.Null(configFocus["DB2:Connection"]);
Assert.Null(configFocus["Source:DB2:Connection"]);
Assert.Equal("MemVal4", configFocus[null]);
}
开发者ID:perezgb,项目名称:Configuration,代码行数:60,代码来源:ConfigurationTest.cs
示例5: Settings
internal Settings(string projectDirectory, string settingsFile)
{
var configuration = new Configuration();
configuration.AddJsonFile(Path.Combine(projectDirectory, settingsFile));
_configuration = configuration;
}
开发者ID:kazuk,项目名称:R4MVC,代码行数:7,代码来源:Settings.cs
示例6: Can_use_connection_string_name_in_OnConfiguring_test
private async Task Can_use_connection_string_name_in_OnConfiguring_test(string connectionName)
{
var configuration = new Configuration
{
new MemoryConfigurationSource(
new Dictionary<string, string>
{
{ "Data:Northwind:ConnectionString", SqlServerTestDatabase.NorthwindConnectionString }
})
};
var serviceCollection = new ServiceCollection();
serviceCollection
.AddInstance<IConfiguration>(configuration)
.AddEntityFramework()
.AddSqlServer();
var serviceProvider = serviceCollection.BuildServiceProvider();
using (await SqlServerTestDatabase.Northwind())
{
using (var context = new NorthwindContext(serviceProvider, connectionName))
{
Assert.Equal(91, await context.Customers.CountAsync());
}
}
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:27,代码来源:ConnectionStringTest.cs
示例7: Main
public Task<int> Main(string[] args)
{
//Add command line configuration source to read command line parameters.
var config = new Configuration();
config.AddCommandLine(args);
var serviceCollection = new ServiceCollection();
serviceCollection.Add(HostingServices.GetDefaultServices(config));
var services = serviceCollection.BuildServiceProvider(_hostServiceProvider);
var context = new HostingContext()
{
Services = services,
Configuration = config,
ServerName = "Microsoft.AspNet.Server.WebListener",
ApplicationName = "BugTracker"
};
var engine = services.GetService<IHostingEngine>();
if (engine == null)
{
throw new Exception("TODO: IHostingEngine service not available exception");
}
using (engine.Start(context))
{
Console.WriteLine("Started the server..");
Console.WriteLine("Press any key to stop the server");
Console.ReadLine();
}
return Task.FromResult(0);
}
开发者ID:jack4it,项目名称:BugTracker,代码行数:32,代码来源:Program.cs
示例8: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
var config = new Configuration()
.AddJsonFile("config.json");
var constr = config.Get("Data:DefaultConnection:ConnectionString");
options.UseSqlServer(constr);
}
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:7,代码来源:ArtistContext.cs
示例9: Startup
/// <summary>
/// Constructor - load the configuration files and store in the
/// static area.
/// </summary>
public Startup()
{
Configuration = new Configuration()
.AddJsonFile("config.json", optional: true)
.AddJsonFile("config-local.json", optional: true)
.AddEnvironmentVariables();
}
开发者ID:ibrahimovfuad,项目名称:blog-code,代码行数:11,代码来源:Startup.cs
示例10: EnvDefaultsToDevelopmentConfigValueIfSpecified
public void EnvDefaultsToDevelopmentConfigValueIfSpecified()
{
var vals = new Dictionary<string, string>
{
{ "ASPNET_ENV", "Staging" }
};
var config = new Configuration()
.Add(new MemoryConfigurationSource(vals));
var context = new HostingContext
{
ServerFactory = this,
Configuration = config
};
var engine = new HostingEngine();
using (engine.Start(context))
{
Assert.Equal("Staging", context.EnvironmentName);
var env = context.ApplicationServices.GetRequiredService<IHostingEnvironment>();
Assert.Equal("Staging", env.EnvironmentName);
}
}
开发者ID:Guruanth,项目名称:Hosting,代码行数:25,代码来源:HostingEngineTests.cs
示例11: Startup
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
开发者ID:jonnoaud,项目名称:FrontEndSeed,代码行数:7,代码来源:Startup.cs
示例12: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var configPath = Path.Combine(appEnv.ApplicationBasePath, "..", "..");
Configuration = new Configuration(configPath).AddJsonFile("config.json").
AddEnvironmentVariables("SmsPrize_");
}
开发者ID:squideyes,项目名称:SmsPrize,代码行数:7,代码来源:Startup.cs
示例13: Startup
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
开发者ID:bigfont,项目名称:Docs,代码行数:7,代码来源:Startup.cs
示例14: ConfigureServices
/// <summary>
/// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
/// </summary>
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
/* TODO: #10
services.AddCaching();
services.AddSession();
services.ConfigureSession(o =>
{
o.IdleTimeout = TimeSpan.FromMinutes(5);
});*/
services.AddTransient<WopiAuthorizationAttribute>();
// Autofac resolution
var builder = new ContainerBuilder();
// Configuration
Configuration configuration = new Configuration();
configuration.AddEnvironmentVariables();
builder.RegisterInstance(configuration).As<IConfiguration>().SingleInstance();
// File provider implementation
var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
var assembly = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));
builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();
builder.Populate(services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
开发者ID:FeodorFitsner,项目名称:WopiHost,代码行数:35,代码来源:Startup.cs
示例15: Configure
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");
config.AddJsonFile("config.dev.json", true);
config.AddUserSecrets();
var password = config.Get("password");
if (config.Get<bool>("RecreateDatabase"))
{
var context = app.ApplicationServices.GetService<Models.BlogDataContext>();
context.Database.EnsureDeleted();
System.Threading.Thread.Sleep(2000);
context.Database.EnsureCreated();
}
if (config.Get<bool>("debug"))
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Home}/{action=Index}/{id?}"));
app.UseFileServer();
}
开发者ID:lukehammer,项目名称:AspNetBlog,代码行数:34,代码来源:Startup.cs
示例16: Startup
public Startup(
IHostingEnvironment hostingEnvironment,
ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Startup>();
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
var loggingConfiguration = configuration.GetSubKey("Logging");
var serilog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithMachineName()
.Enrich.WithProcessId()
.Enrich.WithThreadId();
if (string.Equals(hostingEnvironment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
serilog.WriteTo.ColoredConsole();
}
string elasticSearchConnectionString;
if (loggingConfiguration.TryGet("ElasticSearch:Server", out elasticSearchConnectionString))
{
serilog.WriteTo.ElasticSearch(node: new Uri(elasticSearchConnectionString));
}
loggerFactory.AddSerilog(serilog);
}
开发者ID:Tragetaschen,项目名称:Entropy,代码行数:30,代码来源:Startup.cs
示例17: Configure
public void Configure(IBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddEnvironmentVariables();
// Set up application services
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc();
});
// Enable Browser Link support
app.UseBrowserLink();
// Add static files to the request pipeline
app.UseStaticFiles();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:28,代码来源:Startup.cs
示例18: CommitConfiguration_with_default_config_file
public void CommitConfiguration_with_default_config_file()
{
var toolMock = new Mock<MyMigrationTool>() { CallBase = true };
var args
= new[]
{
"--ContextAssembly=EntityFramework.Design.Tests.dll",
};
var configSourceMock = new Mock<IniFileConfigurationSource>("Foo") { CallBase = true };
var tool = toolMock.Object;
var configuration = new Configuration();
configSourceMock.Setup(m => m.Load());
configSourceMock.Setup(m => m.Commit());
toolMock.Protected()
.Setup<IniFileConfigurationSource>("CreateIniFileConfigurationSource", ItExpr.IsAny<string>())
.Callback<string>(AssertConfigFileCallback2)
.Returns(configSourceMock.Object);
configuration.AddCommandLine(args);
tool.CommitConfiguration(configuration);
toolMock.Protected().Verify<IniFileConfigurationSource>("CreateIniFileConfigurationSource", Times.Once(), ItExpr.IsAny<string>());
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:26,代码来源:MigrationToolTest.cs
示例19: Startup
public Startup(IApplicationEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration(env.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
开发者ID:ForestZheng,项目名称:WebApp-OpenIdConnect-AspNet5,代码行数:7,代码来源:Startup.cs
示例20: Startup
public Startup(IHostingEnvironment env)
{
var configuration = new Configuration()
.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
开发者ID:huamanhtuyen,项目名称:FindAroundWS,代码行数:8,代码来源:Startup.cs
注:本文中的Microsoft.Framework.ConfigurationModel.Configuration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论