Why doesn't DoIt() method call get intercepted? Should I use something other than InterfaceInterceptor to intercept the DoIt() method? How would you do it?
using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
namespace UnityTest
{
class Program
{
static void Main(string[] args)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<ILogger, Logger>();
container.Configure<Interception>().SetInterceptorFor<ILogger>(new InterfaceInterceptor());
var logger = container.Resolve<ILogger>();
logger.Write("World.");
Console.ReadKey();
}
}
public interface ILogger
{
void Write(string message);
[Test]
void DoIt(string message);
}
public class Logger : ILogger
{
public void Write(string message)
{
DoIt(message);
}
public void DoIt(string message)
{
Console.Write(message);
}
}
public class TestAttribute : HandlerAttribute
{
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new TestHandler();
}
}
public class TestHandler : ICallHandler
{
public int Order { get; set; }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.Write("Hello, ");
return getNext()(input, getNext);
}
}
}