當前位置: 首頁>>代碼示例>>C#>>正文


C# ConfigurationModel.Configuration類代碼示例

本文整理匯總了C#中Microsoft.Framework.ConfigurationModel.Configuration的典型用法代碼示例。如果您正苦於以下問題:C# Configuration類的具體用法?C# Configuration怎麽用?C# Configuration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Configuration類屬於Microsoft.Framework.ConfigurationModel命名空間,在下文中一共展示了Configuration類的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());
            });

#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


注:本文中的Microsoft.Framework.ConfigurationModel.Configuration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。