Policy and Interceptions with Unity

Topics: General discussion, Policy Injection Application Block
Jun 27, 2013 at 5:34 PM
Edited Jun 28, 2013 at 11:26 AM
I'm experimenting on making an AOP-Based library, here is what I have and the problem

The Question :

Why the Invoke in the Call Handler is never called ?

Attribute :
[AttributeUsage(AttributeTargets.Method)]
public class LoggingAttribute : HandlerAttribute
{        
    public override ICallHandler CreateHandler(IUnityContainer container)
    {
        return new LoggingCallHandler();
    }
Call Handler
public class LoggingCallHandler : ICallHandler {

    private mLogger _Logger;
    private mLogger Logger
    {
        get
        {
            if (_Logger == null)
                _Logger = new mLogger();
            return _Logger;
        }
        set
        {
            _Logger = value;
        }
    }

    public IMethodReturn Invoke(IMethodInvocation input,
      GetNextHandlerDelegate getNext)
    {}
Container Setup and Registerations
    public void SetUp()
    {
        container.AddNewExtension<Interception>();

        //register types
        container.RegisterType<MainWindowViewModel>();
        container.RegisterType<DummyModel>();

        // This works correctly , shouldn't be related to the question
        PolicyDefinition policy = container.Configure<Interception>().
            SetInterceptorFor<DummyModel>(new VirtualMethodInterceptor()).
            SetInterceptorFor<MainWindowViewModel>(new VirtualMethodInterceptor()).AddPolicy("NotifyPolicy");

        PolicyDefinition policyLog = container.Configure<Interception>().
            SetInterceptorFor<DummyModel>(
            new VirtualMethodInterceptor()).
            SetInterceptorFor<MainWindowViewModel>(
            new VirtualMethodInterceptor()).AddPolicy("LoggingPolicy");

        policy.AddMatchingRule(new PropertyMatchingRule("*", PropertyMatchingOption.Set));
        policy.AddCallHandler<NonAttributedINPCHandler>();

        // Here is the important part !!!
        CustomAttributeMatchingRule ruleLog = new CustomAttributeMatchingRule(typeof(LoggingAttribute), true);            
        policyLog.AddMatchingRule(ruleLog)
                 .AddCallHandler<LoggingCallHandler>();       
    }
no doubt , in code :

lots of [Logging]s were used

I think I've posted the necessary parts, If there is anything missed inform me.

I have doubt on the "Matching Rules" and Interception part.

Get the code from here :
http://sdrv.ms/11Q6VdW
The Question :

Why the Invoke in the Call Handler is never called ?
Jun 28, 2013 at 4:44 PM
Edited Jul 10, 2013 at 4:59 PM
See: http://unity.codeplex.com/discussions/448429

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to