policyInjection and config file

Topics: Policy Injection Application Block
Jul 21, 2008 at 12:24 PM
Edited Jul 21, 2008 at 12:26 PM
Hi, all.

I've started using PolicyInjection and I have a problem with my config file.
Then I specify all settings in App.config file - all work.
But then I specify another config file - policy injection don't work!
What is not correct?

I specify config file thereby:

ExeConfigurationFileMap

map = new ExeConfigurationFileMap();
map.ExeConfigFilename = "my.config"
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);  
UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("MySection"); 
IUnityContainer _Container = new UnityContainer(); 
section.Containers["Initialization"].Configure(_Container);


my.config:

<
configuration>
<
configSections>
<
section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<
section name="MySection" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
</
configSections>   

 <
CfgMigrator configSource="MySection.config" /> 

<
policyInjection>
<
policies>
<
add name="NamespaceMatchingRule">
<
matchingRules>
<
add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.NamespaceMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Namespace Matching Rule">
<
matches>
<
add match="MyNamespace" ignoreCase="false" />
</matches>
</
add>
</
matchingRules>
<
handlers>
<
add order="0" type="MyHandler, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Custom Handler" />
</
handlers>
</
add>
</
policies>
</
policyInjection>  

</
configuration>

 

 

 

 

 

 

 

 

Jul 21, 2008 at 12:41 PM
Hi,

You're showing how you are configuring the Unity container, but that doesn't affect where PIAB gets its configuration from. If you want to use PIAB with configuration from a file different than the app's configuration file, you can use the approach described in http://msdn.microsoft.com/en-us/library/cc511890.aspx.

Hope this helps,
Fernando

_Svetlana_ wrote:
Hi, all.

I've started using PolicyInjection and I have a problem with my config file.
Then I specify all settings in App.config file - all work.
But then I specify another config file - policy injection don't work!
What is not correct?

I specify config file thereby:

ExeConfigurationFileMap

map = new ExeConfigurationFileMap();
map.ExeConfigFilename = "my.config"
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);  
UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("MySection"); 
IUnityContainer _Container = new UnityContainer(); 
section.Containers["Initialization"].Configure(_Container);


my.config:

<
configuration>
<
configSections>
<
section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<
section name="MySection" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
</
configSections>   

 <
CfgMigrator configSource="MySection.config" /> 

<
policyInjection>
<
policies>
<
add name="NamespaceMatchingRule">
<
matchingRules>
<
add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.NamespaceMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Namespace Matching Rule">
<
matches>
<
add match="MyNamespace" ignoreCase="false" />
</matches>
</
add>
</
matchingRules>
<
handlers>
<
add order="0" type="MyHandler, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Custom Handler" />
</
handlers>
</
add>
</
policies>
</
policyInjection>  

</
configuration>

 

 

 

 

 

 

 

 




Jul 21, 2008 at 12:58 PM

I create my object:   
IMyCalls myCalls  = PolicyInjection.Create<MyCalls, IMyCalls>();

then call function:
myCalls
.Call1();


and I expect, that MyHandler intercepts this call. But it don't work.

[

ConfigurationElementType(typeof(CustomCallHandlerData))]
class MyHandler : ICallHandler
{
public MyHandler(NameValueCollection col)
{
}

public
int Order { get; set; }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
return getNext()(input, getNext);
}

 

Jul 21, 2008 at 1:52 PM

I've found decision.


IConfigurationSource

source = new FileConfigurationSource("my.config");

UnityConfigurationSection section = (UnityConfigurationSection)source.GetSection("MySection"); 
IUnityContainer _Container = new UnityContainer(); 
section.Containers["Initialization"].Configure(_Container);

IMyCalls myCalls  = PolicyInjection.Create<MyCalls, IMyCalls>(source);