1. Let us imagine we need to split into two files, so your root config file will look like below
<configSections
>
<
section name="unitySection1"
type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
Microsoft.Practices.Unity.Configuration"/>
<
section name="
unitySection2
"
type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
Microsoft.Practices.Unity.Configuration"/>
<
/configSections>
<
unitySection1
configSource="unity1.config" />
<
unitySection2
configSource="unity2.config" />
2. And your individual unity files will look like below(see the highlighted section that 'unity' tag becomes 'unitySection1')
<unitySection1>
<container />
</unitySection1>
<unitySection2>
<container />
</unitySection2>
3. Load the separate configuration files into Container
UnityContainer.LoadConfiguration - will adds up the container details, so we just need to call it twice
private void Initialise()
{
string[] unitySections = new string[] {"unitySection1", "
unitySection2
"};
IUnityContainer container = new UnityContainer();
foreach(var section in unitySections)
{
var configuration = ConfigurationManager.OpenExeConfiguration(path);
var unitySection = (UnityConfigurationSection)
configuration.
GetSection(section); container.
LoadConfiguration(unitySection);
}
}
reference link
No comments:
Post a Comment