Interception does not recognize an attribute set on the Interface

Topics: Enterprise Library Core, General discussion, Policy Injection Application Block, Semantic Logging Application Block
Feb 18, 2015 at 7:39 AM
Edited Feb 19, 2015 at 9:38 AM
My interception is not working when I call the method InsertTipPoco in my implementing class. The WriteTrace does not get called when I call the InsertTipPoco method through my class which implements the interface.
Following are the libraries and its versions referenced in the project which contains the Class TipPocoRepository and the Interface ITipPocoRepository
• Microsoft.Practices.EnterpriseLibrary.Common (Version 6.0.0.0)
• Microsoft.Practices.EnterpriseLibrary.Logging (Version 6.0.0.0)
• Microsoft.Practices.ServiceLocation (Version 1.3.0.0)
• Microsoft.Practices.Unity (Version 3.5.0.0)
• Microsoft.Practices.Unity.Configuration (Version 3.5.0.0)
• Microsoft.Practices.Unity.Interception (Version 3.5.0.0)
• Microsoft.Practices.Unity.Interception.Configuration (Version 3.5.0.0)
• Microsoft.Practices.Unity.RegistrationByConvention (Version 3.5.0.0)

Following is the code I have implemented in my application.

Object instantiation via Unity:
var IocResolver = new UnityContainer().LoadConfiguration();

var tipPocoRepository = IocResolver.Resolve<ITipPocoRepository>();

tipPocoRepository.InsertTipPoco(tipPoco);
Consuming Interface:
namespace TipManagement
{
    using System.Collections.Generic;
 
    public interface ITipPocoRepository
    {
        [WriteTrace]
        ITipPoco InsertTipPoco(ITipPoco tipPoco);
    }
}
Class implementing consuming interface:
namespace TipManagement
{
 
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data.Common;
 
    public class TipPocoRepository : ITipPocoRepository
    {    
        private Guid key; 
        private bool disposed; 
        private TransactionalDbContext dbContext;        
 
        public ITipPoco InsertTipPoco(ITipPoco TipPoco)
        {            
            var insertQuery = dbContext.Tips.Add(tipPoco as TipPoco);            
            Save();
            return tipPoco;
        }
 
        
        public TipPocoRepository(TransactionalDbContext transactionalDbContext)
        {
            dbContext = transactionalDbContext;
        }
    [InjectionConstructor]
        public TipPocoRepository()
        {
            dbContext = new TransactionalDbContext();
        }
  
 
        public void Save()
        {
            dbContext.SaveChanges();
        }
 
    }
HandlerAttribute Implementation:
namespace Tracing
{ 
    using Microsoft.Practices.Unity.InterceptionExtension;
    using System.Configuration;
 
 
    public sealed class WriteTrace : HandlerAttribute
    {
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            return new WriteTraceCallHandler();
        }
    }
}
ICallHandler Implementation:
namespace Tracing
{
 
    using Microsoft.Practices.Unity.InterceptionExtension;
    using System;
    using System.Configuration;
    using System.Linq;
    using System.Reflection;
 
    internal class WriteTraceCallHandler : ICallHandler
    {
 
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {            
                string methodName = input.MethodBase.ToString(); 
                                                
                //logic to write trace before method executes
                IMethodReturn result = getNext()(input, getNext); 
                return result;
        }
 
        public int Order { get; set; }
    }
}