Unity Configuration

Mar 11, 2008 at 11:56 PM
It would be nice if Unity configuration wasn't so tightly coupled to the System.Configuration namespace. I'm using unity in a plugin application, my app doesn't and won't have a configuration file. If I could include the configuration as an embedded resource as .xml and deserialize it as a standard xml type it would be nice. Any plans to support this? or something I'm missing?
Mar 12, 2008 at 12:42 AM
Ok, well I was able to get around the problem by using a linked config file:

IUnityContainer container = new UnityContainer();

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = cfgPath + @"\MyApp.dll.config";
if (!File.Exists(fileMap.ExeConfigFilename)) { return; }
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");

This worked...
Mar 12, 2008 at 6:40 AM
We don't have any plans in this release to do more generalized config. Our current approach is to concentrate on building the configuration API for the container, build a basic configuration file system that the container is decoupled from, then wait and see what happens.
Mar 13, 2008 at 2:17 AM
Zapbbx, nice work around!

Do you know if you could pull configuration information from sources other than xml?

This might sound strange but one of the projects I am converting as 100's of components. I was hoping to pull the configuration from a database. I would then be able to make an interface to that database. Even change the database then reload it during live operation.

Bryan Reynolds
Mar 13, 2008 at 4:26 AM
Hi Brian,

I'm working on something like that right now. I've got a good section of it done, but got side tracked on another project the last two weeks. The biggest challenge is that it's a little harder to unit test and often times your DB connection is something you want to build. As the unity contib project comes up I'll try to post some work there to give you some ideas.
Oct 20, 2008 at 11:15 PM
I have something similar but it is still not clean. I have this:

Assembly assembly = Assembly.GetExecutingAssembly();           
Stream path = assembly.GetManifestResourceStream(ass.GetName().Name + "." +    "Application.config");
XmlDocument myDocument = new XmlDocument();
myDocument.PreserveWhitespace = true;
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = "Application.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(
       map, ConfigurationUserLevel.None);
UnityConfigurationSection section
      = (UnityConfigurationSection)config.GetSection("unity");

I would like to try to avoid going to disk if I can for Configuration Object to work. If this can be avoided, I will be happy.