From e1ce734be28092ddf8607e7ec4224f581a12f27b Mon Sep 17 00:00:00 2001 From: Lukas Gerbenis Date: Mon, 14 Sep 2015 17:32:53 +0300 Subject: [PATCH] #3 Updated configuration to support xml format --- .../BetterModulesServiceCollectionExtensions.cs | 7 +++++-- .../Config/connectionStrings.config | 3 +++ .../BetterModules.Mvc6.Sandbox/Config/modules.config | 7 +++++++ .../BetterModules.Mvc6.Sandbox/Config/modules.json | 12 +++++------- vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs | 2 ++ vNext/src/BetterModules.Mvc6.Sandbox/config.json | 5 ----- vNext/src/BetterModules.Mvc6.Sandbox/project.json | 7 ++++--- 7 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 vNext/src/BetterModules.Mvc6.Sandbox/Config/connectionStrings.config create mode 100644 vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.config diff --git a/vNext/src/BetterModules.Core/Extensions/BetterModulesServiceCollectionExtensions.cs b/vNext/src/BetterModules.Core/Extensions/BetterModulesServiceCollectionExtensions.cs index 4e08dee..eee1eb0 100644 --- a/vNext/src/BetterModules.Core/Extensions/BetterModulesServiceCollectionExtensions.cs +++ b/vNext/src/BetterModules.Core/Extensions/BetterModulesServiceCollectionExtensions.cs @@ -56,10 +56,13 @@ private static void ConfigureDefaultServices(IServiceCollection services) private static void LoadConfiguration(IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration.GetSection("modulesSettings")); + services.Configure(configuration); var provider = services.BuildServiceProvider(); var config = provider.GetService>().Options; - config.Database.ConnectionString = configuration[config.Database.ConnectionStringName]; + if (config?.Database != null) + { + config.Database.ConnectionString = configuration[config.Database.ConnectionStringName]; + } services.AddInstance(config); } diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/Config/connectionStrings.config b/vNext/src/BetterModules.Mvc6.Sandbox/Config/connectionStrings.config new file mode 100644 index 0000000..2ad5b1c --- /dev/null +++ b/vNext/src/BetterModules.Mvc6.Sandbox/Config/connectionStrings.config @@ -0,0 +1,3 @@ + + + diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.config b/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.config new file mode 100644 index 0000000..97badb3 --- /dev/null +++ b/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.config @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.json b/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.json index 5465576..e58c85d 100644 --- a/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.json +++ b/vNext/src/BetterModules.Mvc6.Sandbox/Config/modules.json @@ -1,10 +1,8 @@ { - "modulesSettings": { - "webSiteUrl": "http://BetterModules.core.tests", - "database": { - "schemaName": "dbo", - "connectionStringName": "BetterModulesTests", - "databaseType": "MsSql2008" - } + "webSiteUrl": "http://BetterModules.core.tests", + "database": { + "schemaName": "dbo", + "connectionStringName": "BetterModulesTests", + "databaseType": "MsSql2008" } } diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs b/vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs index 704a4da..8985cd3 100644 --- a/vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs +++ b/vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs @@ -19,6 +19,8 @@ public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true) .AddJsonFile("Config/modules.json") .AddJsonFile("Config/connectionStrings.json"); + //.AddXmlFile("Config/modules.config") + //.AddXmlFile("Config/connectionStrings.config"); if (env.IsDevelopment()) { diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/config.json b/vNext/src/BetterModules.Mvc6.Sandbox/config.json index efa1d6a..f77f07a 100644 --- a/vNext/src/BetterModules.Mvc6.Sandbox/config.json +++ b/vNext/src/BetterModules.Mvc6.Sandbox/config.json @@ -1,10 +1,5 @@ { "AppSettings": { "SiteTitle": "BetterModules.Mvc6.Sandbox" - }, - "Data": { - "DefaultConnection": { - "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-BetterModules.Mvc6.Sandbox-b140b676-8027-4d3e-a391-dc91b5e50f82;Trusted_Connection=True;MultipleActiveResultSets=true" - } } } diff --git a/vNext/src/BetterModules.Mvc6.Sandbox/project.json b/vNext/src/BetterModules.Mvc6.Sandbox/project.json index ab3f43c..f304742 100644 --- a/vNext/src/BetterModules.Mvc6.Sandbox/project.json +++ b/vNext/src/BetterModules.Mvc6.Sandbox/project.json @@ -12,14 +12,15 @@ "Microsoft.AspNet.StaticFiles": "1.0.0-beta6", "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6", "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7", - "Microsoft.Framework.Configuration.Json": "1.0.0-beta6", - "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta6", + "Microsoft.Framework.Configuration.Json": "1.0.0-beta7", + "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7", "Microsoft.Framework.Logging": "1.0.0-beta7", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta6", "BetterModules.Core": "1.0.0-*", "BetterModules.Sample.Module": "1.0.0-*", "Microsoft.Framework.Logging.EventLog": "1.0.0-beta7", - "Microsoft.Framework.Logging.Console": "1.0.0-beta7" + "Microsoft.Framework.Logging.Console": "1.0.0-beta7", + "Microsoft.Framework.Configuration.Xml": "1.0.0-beta7" }, "commands": {