当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.AddJsonFile方法代码示例

本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration.AddJsonFile方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.AddJsonFile方法的具体用法?C# Configuration.AddJsonFile怎么用?C# Configuration.AddJsonFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Framework.ConfigurationModel.Configuration的用法示例。


在下文中一共展示了Configuration.AddJsonFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: Configure

        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                services.AddAssembly(this);

                // Add EF services to the services container
                services.AddEntityFramework()
                    .AddSqlServer();

                // Configure DbContext
                services.SetupOptions<DbContextOptions>(options =>
                {
                    options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
                });
                
                //// Add Identity services to the services container
                //services.AddIdentitySqlServer<ApplicationDbContext, ApplicationUser>()
                //    .AddAuthentication();

                // Add MVC services to the services container
                services.AddMvc();

                services.AddTransient(typeof(IService1), typeof(Service1));
            });

            // Enable Browser Link support
            //app.UseBrowserLink();

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType,
                LoginPath = new PathString("/Account/Login"),
            });

            // 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:david-driscoll,项目名称:DependencyInjection.Annotations,代码行数:58,代码来源:Startup.cs

示例5: 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="applicationEnvironment">The location the application is running in</param>
        /// <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(
            IApplicationEnvironment applicationEnvironment,
            IHostingEnvironment hostingEnvironment)
        {
            // Beta 5 update
            //ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(
            //  applicationEnvironment.ApplicationBasePath);
            
            Configuration configuration = new Configuration();

            // Add configuration from the config.json file.
            configuration.AddJsonFile("config.json");

            // Add configuration from an optional config.development.json, config.staging.json or 
            // config.production.json file, depending on on the environment. These settings override the ones in 
            // the config.json file.
            configuration.AddJsonFile($"config.{hostingEnvironment.EnvironmentName}.json", optional: true);

            if (hostingEnvironment.IsEnvironment(EnvironmentName.Development))
            {
                // This reads the configuration keys from the secret store. This allows you to store connection strings
                // and other sensitive settings on your development environment, 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
                configuration.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
            configuration.AddEnvironmentVariables();

            // return configurationBuilder.Build();
            return configuration;
        }
开发者ID:TukekeSoft,项目名称:ASP.NET-MVC-Boilerplate,代码行数:53,代码来源:Startup.Configuration.cs

示例6: Get

        public static ApiConfigDetails Get(string configPath)
        {
            var apiConfig = new ApiConfigDetails();

            var config = new Configuration();
            config.AddJsonFile(configPath);

            apiConfig.ApiKey = config.Get("SimpleConfigServiceApiKey");
            apiConfig.UriFormat = config.Get("SimpleConfigServiceUriFormat");

            return apiConfig;
        }
开发者ID:antonyfrancis,项目名称:simple-config-service,代码行数:12,代码来源:ConfigReader.cs

示例7: ConfigSetup

        public ConfigSetup()
        {
            // Make individual calls to AddXXX extension methods
            var config = new Configuration();
            config.AddJsonFile("config.json");
            config.AddEnvironmentVariables();

            // Fluent configuration
            var configFluent = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }
开发者ID:bigfont,项目名称:Docs,代码行数:12,代码来源:ConfigSetup.cs

示例8: Configure

        public void Configure(IBuilder app)
        {
            // Enable Browser Link support
            app.UseBrowserLink();

            // Setup configuration sources
            var configuration = new Configuration();

            //configuration.AddIniFile("config.ini");
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            //app.Run(async context =>
            //{
            //    await context.Response.WriteAsync(configuration.Get("Data:Configuration"));
            //});

            app.Run(async context =>
            {
                var asm = Assembly.Load(new AssemblyName("klr.host"));
                var assemblyVersion = asm.GetCustomAttribute<AssemblyInformationalVersionAttribute>();

                await context.Response.WriteAsync(assemblyVersion.InformationalVersion);
            });

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container
                services.AddEntityFramework().AddInMemoryStore();
                services.AddScoped<PersonContext>();

                // Add MVC services to the services container
                services.AddMvc();
            });

            // 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:julid29,项目名称:confsamples,代码行数:52,代码来源:Startup.cs

示例9: TestConfig

        public TestConfig()
        {
            _dataSource = Environment.GetEnvironmentVariable("PERFRUN_DataSource");
            RuntimeFlavor = getRuntimeFlavor();

            var resultsDirectory = Environment.GetEnvironmentVariable("PERFRUN_ResultsDirectory");
            ResultsDirectory = string.IsNullOrEmpty(resultsDirectory) ? ResultsDirectory : resultsDirectory;

            const string cliConfigPath = "LocalConfig.json";
            const string vsConfigPath = "..\\..\\LocalConfig.json";

            if (_dataSource != null)
            {
                RunPerfTests = true;
            }
            else
            {
                var configuration = new Configuration();
                if (File.Exists(cliConfigPath))
                {
                    configuration.AddJsonFile(cliConfigPath);
                }
                else if (File.Exists(vsConfigPath))
                {
                    configuration.AddJsonFile(vsConfigPath);
                }

                if (configuration.TryGet("Data:DefaultDataSource:DataSource", out _dataSource))
                {
                    _dataSource = _dataSource.Trim();
                    string runPerfTests;
                    configuration.TryGet("Data:RunPerfTests", out runPerfTests);
                    RunPerfTests = !string.IsNullOrEmpty(runPerfTests) && !runPerfTests.ToLower().Equals("false");
                }
            }
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:36,代码来源:TestConfig.cs

示例10: Configure

        public void Configure(IApplicationBuilder app)
        {
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapModuleRoute();

                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
开发者ID:Tragetaschen,项目名称:Entropy,代码行数:18,代码来源:Startup.cs

示例11: Configure

        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container
                services.AddEntityFramework()
                    .AddSqlServer();

                // Configure DbContext
                services.SetupOptions<DbContextOptions>(options =>
                {
                    options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
                });

                // 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" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:43,代码来源:Startup.cs

示例12: Startup

        public Startup()
        {
            var configuration = new Configuration()
                 .AddJsonFile("config.json");

            if (Program.Environment.OtherArgs != null)
            {
                configuration.AddCommandLine(Program.Environment.OtherArgs);
            }

            // Use the local omnisharp config if there's any in the root path
            if (File.Exists(Program.Environment.ConfigurationPath))
            {
                configuration.AddJsonFile(Program.Environment.ConfigurationPath);
            }

            configuration.AddEnvironmentVariables();

            Configuration = configuration;
        }
开发者ID:ryanrousseau,项目名称:omnisharp-roslyn,代码行数:20,代码来源:Startup.cs

示例13: Configure

		public void Configure(IApplicationBuilder app)
        {
			// For more information on how to configure your application, 
			// visit http://go.microsoft.com/fwlink/?LinkID=398940

			// Setup configuration sources
			Configuration configuration = new Configuration();

			configuration.AddJsonFile("config.json");
			configuration.AddIniFile("config.ini");
			// this cannot be accessed if XML fomratters were removed
			configuration.AddXmlFile("config.xml");
			configuration.AddEnvironmentVariables();

			string url_home = configuration.Get<string>("UrlLogo");

			app.UseMvc();
			app.UseWelcomePage();

			return;
		}
开发者ID:moljac,项目名称:Ph4ct3x,代码行数:21,代码来源:Startup.cs

示例14: Configure

        public void Configure(IBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();
            configuration.AddJsonFile("Config.json");
            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" });

                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{controller}/{action}/{area}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:38,代码来源:Startup.cs

示例15: LoadConfigurationFile

        /// <summary>
        /// Loads a json configuration file
        /// </summary>
        internal IConfiguration LoadConfigurationFile(IFile configFile)
        {
            var configuration = new Microsoft.Framework.ConfigurationModel.Configuration();
            configuration.AddJsonFile(configFile.FullPath);

            return configuration;
        }
开发者ID:ap0llo,项目名称:MusicFileCop,代码行数:10,代码来源:ConfigurationLoader.cs


注:本文中的Microsoft.Framework.ConfigurationModel.Configuration.AddJsonFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。