DAAB ConnectionString extensibilty?

Topics: Data Access Application Block, Enterprise Library Core
Feb 15, 2010 at 6:56 PM

I was wondering if there is some way to extend the locations where the DAAB will look for connection strings when resolving a Database dependency?

Specifically, I have DAO objects defined in my unity container, which take a Database as a constructor argument. I can define this param as a dependency either with an attribute like this:

MyDao([Dependency("MyDB")] Database database)

Or in the configuration like this:

    <param name="database" type="Database">
      <dependency name="MyDB" />

The dependency gets resolved using the connection string in App.config/Web.config with the name "MyDB". However, I am using ExeConfigurationFileMap to load external config files with my unity configurations from separate files. If I still define the connection string(s) in the main config file, this works fine, but I would like to move them into the mapped files as well, and have them used for dependency resolution. Is there some way to do this without modifying the actual DAAB code which creates the Database('s) (implement some abstract factory and plug it in, perhaps)?


Feb 16, 2010 at 12:57 AM

You just need to point the <connectionStrings> section to the external config file you want to use. 

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = "test.exe.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
config.ConnectionStrings.SectionInformation.ConfigSource = "daab.config";


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.