Unity Configuration For Modules

Aug 4, 2008 at 6:49 PM

Hi: I want my Modules to have an external configuration file with some sections for Unity.  It seems that System.Configuration is not really setup to do this in the sense that obviously I"m not trying to add sections or additional container element configuration the traditional way through union of settings into app.exe.config. 

When I use System.Configuration to read a module.config file separate from the app.config and produce a UnityContainerElement the result is as expected; e.g. the UnityContainerElement is created with the type elements and other configuration that I am expecting.  Everything looks as 'normal' as I can judge not having knowledge of all the details.  The type elements with the mapping and system.type information looks correct.

Then I make a child container from the passed in Container and configure it using the UnityContainerElement.


IUnityContainer childContainer = Container.CreateChildContainer();



However none of the types loaded into the child container can be resolved for some reason ???


b = UnityContainerHelper.IsTypeRegistered( childContainer , typeof( IMenuBarMgr ) )();

I was just wondering if this makes sense.  Should I even be trying to 'merge' external configuration like this into child containers ?  I know that I can't seem to get the types out even though looking in the debugger the configuration has been fread from the config file and all the type mappings are loaded into the Microsoft.Practices.Unity.Configuration.UnityContainerElement .




fileMap = new ExeConfigurationFileMap();


fileMap.ExeConfigFilename = moduleFilePath;


Configuration moduleConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);




UnityConfigurationSection section = (UnityConfigurationSection)moduleConfig.GetSection("unity");



UnityContainerElement containerElement = section.Containers["AppModuleContainer"];



IUnityContainer childContainer = _Container.CreateChildContainer();





Just wondering ?  I"m fairly new to the CAG and this is my first shot at dynamically loading modules.  I wanted the modules to use a DI Container and I did not want to 'share' the app.exe.config file with the modules.  I wanted them to have their own external configuration for the DI Container.

thanks in advance


Aug 5, 2008 at 1:53 AM
Edited Aug 5, 2008 at 1:54 AM
As ctavares noted in the Unity forum, Newbie: How to get unity to look in specific directory, you can load external config files.   I created you a working demo in the latest drop of my ShellApp and provided documentation references and places to get more code examples HERE.
Aug 5, 2008 at 2:27 AM





I'll try it out tonight...