Friday, 18 May 2012

structuremap 2.6 IncludeConfigurationFromConfigFile=true not working

When we are using structuremap 2.6.x  and adding structuremap configuration in the app.config/web.config. To  include configuration every one set the property IncludeConfigurationFromConfigFile=true. It is not working and seems to be not implemented. But when we are refering same app.config with AddConfigurationFromXmlFile(configfilepath) then it is working fine. when we are using app.config the file name of configuration is changed after the solution build. To include that configuration file find the solution below.
To get the name and path of configuration file as follows
var configName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; 
The example method and usage as follows:

 private static IContainer InitiazlizeFromAppConfigOrWebConfig()
 {
   var configName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; 
    return new Container(x =>
    {
     x.AddConfigurationFromXmlFile(configName);
      //x.IncludeConfigurationFromConfigFile = true; //seems not imeplemented
    });
}

No comments:

Post a Comment