DCSIMG
עמוד הבית| חבילות השירות שלנו| חומר חופשי| צור קשר
Loading Unity Configuration From Alternative Source - בלוג היועצים של מיקרוסופט ישראל

בלוג היועצים של מיקרוסופט ישראל

Loading Unity Configuration From Alternative Source

In my previous post , I’ve showed you how to use unity schema in web.config for mapping interface types against concrete types.

If you have multiples mappings or you just don’t want to store unity configuration in your web.config , than you can load unity configuration information into container from a specific named configuration file by using System.Configuration.Configuration

 

In order to load Unity configuration from alternative configuration file, change the  UnityServiceHost class from the previous example to look like the following:

 

protected override void InitializeRuntime(){
  ExeConfigurationFileMap map = new ExeConfigurationFileMap();
  map.ExeConfigFilename = @"c:\OtherPlace\UnityDemoConfiguration.config";
  Configuration config = ConfigurationManager.OpenMappedExeConfiguration
(map, ConfigurationUserLevel.None); IUnityContainer container = new UnityContainer(); UnityConfigurationSection section =
(UnityConfigurationSection)config.GetSection("unity"); section.Containers.Default.Configure(container); Extensions.Add(new UnityExtension(container)); base.InitializeRuntime();
}

The map.ExeConfigFilename property point to the alternative source file.

שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 3 and 5 and type the answer here:


Enter the numbers above: