I am creating a WPF application that has a classic architecture: user interface layer, business logic layer, and infrastructure layer. I decided to split the configuration into two files: the app.config file, which contains the general configuration of the application, and dll.config, which contains the connection string for use in DbContext to store the domain model. The second .config file must be attached to the business logic DLL, and the first file is attached to the corresponding user interface executable (there will be another user interface with its own configuration).
app.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> <enterpriseLibrary.ConfigurationSource selectedSource="Winter DAL Configuration"> <sources> <add name="Winter DAL Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="dll.config" /> </sources> </enterpriseLibrary.ConfigurationSource> </configuration>
dll.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> <dataConfiguration defaultDatabase="WinterContext" /> <connectionStrings> <add name="WinterContext" connectionString="Data Source=Winter.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> </configuration>
Now, when I launch the application, DbContext throws an exception saying that it cannot find the connection string with the specified name. If I translate the connection string from dll.config to app.config, everything works fine.
Maybe I should explicitly load the configuration somehow? Or? .. What am I doing wrong?
thanks in advance!
Danil source share