2

DatabaseFactory previously used ConnectionString to create database. Now DatabaseProviderFactory uses ConfigurationSource which basically works on MVC 5 structure of web.config in XML form.

Previously we could do something like below:

   string stConnName = Configuration["Data:DefaultConnection:ConnectionString"];
   string stProvider = Configuration["Data:DefaultConnection:ProviderName"];
   Database oDb = DatabaseFactory.CreateDatabase(stConnName);

Any idea about how to get JSON based database configurations as currently being mentioned in MVC 6 (appsettings.json) for EnterpriseLibrary 6 DatabaseProviderFactory, in order to create generic Database, something like below, which only works with MVC 5's web.config files of XML form:

    FileConfigurationSource fileConfig = new FileConfigurationSource("web.config");
    DatabaseProviderFactory dbProvider = new DatabaseProviderFactory(fileConfig);
    Database oDb = dbProvider.Create("DefaultConnection");
CandleCoder
  • 1,387
  • 4
  • 21
  • 45
Umair Malhi
  • 565
  • 1
  • 5
  • 16
  • I tried to Add Enterprise Library to MVC6 but it is not supported ,if you asking how to get ConnectionString in Appsetting.Json Here is now I do it in Startup.cs 'code' public static string ConnectionString { get; private set; } 'code' and in Constructor I set the value 'code' ConnectionString = Configuration.Get("Data:DefaultConnection:ConnectionString");'code' I wish this help – khaled Dehia Feb 26 '16 at 03:00
  • I couldn't get the answer to this so left this approach and used Custom solution. Getting Connection string was not an issue, I couldn't find the Enterprise Library approach for using Connection string. As it only uses Connection String Name. – Umair Malhi Nov 28 '16 at 06:38

0 Answers0