Any advice would be greatly appreciated on this.
I have a standard NTier application which implements Unity DI. This works absolutely fine, the unity container is created and registers everything within the BAL. I've also got interface interception configured using attribute decoration above methods. I'm trying to measure timings for certain methods. The interface interception works absolutely fine in the BAL layer but when I try to use the same method on say a layer called DistributionProviders which is referenced by the BAL it never hits the call handler.
The code I'm using to configure the interface interception is:
_container.AddNewExtension<Interception>()
.Configure<Interception>()
.SetInterceptorFor<ISftpState>(new InterfaceInterceptor());
The Attribute is class is:
public class ProcessLoggingAttribute : HandlerAttribute
{
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new ProcessLoggingHander();
}
}
The ProcessLoggingHandler is:
public class ProcessLoggingHander : ICallHandler
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.WriteLine("Starting");
var methodReturn = getNext().Invoke(input, getNext);
Console.WriteLine("finishing");
return methodReturn;
}
public int Order { get; set; }
}
Example interface method decoration:
public interface ISftpState
{
[ProcessLogging]
bool Connect();
}
Can anyone explain to me what I'm doing wrong. The only thing I can think of is that the container is not being passed into the CreateHandler() method of the HandlerAttribute.
--Additional Code - This is how I'm registering the Unity Container. Its actually a property within a singleton. I just resolve the top level control class which then automatically resolves the other classes beneath it.
UnityContainer _container = new UnityContainer();
_container.RegisterType<ISftpState,SftpState>();