using System.Collections.Generic;
using Unity.Interception;
using Unity.Interception.ContainerIntegration;
using Unity.Interception.Interceptors.TypeInterceptors.VirtualMethodInterception;
using Unity.Interception.InterceptionBehaviors;
using Unity.Interception.PolicyInjection.Pipeline;
public static void Main()
var container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<IService,Service>(new Interceptor<VirtualMethodInterceptor>(),new InterceptionBehavior<ServiceInterceptor>());
container.RegisterType<IService2,Service2>();
Console.WriteLine("Resolve and call SayHello after interception registered");
var s1 = container.Resolve<IService>();
var s2 = container.Resolve<IService2>();
public interface IService
void SayHello(int prova);
public class Service: IService
public virtual void SayHello()
Console.WriteLine("Hello from Service");
public virtual void SayHello(int prova)
Console.WriteLine(String.Format("Hello from Service{0}",prova));
public interface IService2
public class Service2: IService2
private readonly IService _service;
public Service2(IService Service)
public virtual void SayHello()
public class ServiceInterceptor : IInterceptionBehavior
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
Console.WriteLine(String.Format("Invoking method {0} at {1}",input.MethodBase, DateTime.Now.ToLongTimeString()));
var result = getNext()(input, getNext);
public IEnumerable<Type> GetRequiredInterfaces()
public class ExeInterceptor : IInterceptionBehavior
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
Console.WriteLine(String.Format("Invoking method {0} at {1}",input.MethodBase, DateTime.Now.ToLongTimeString()));
var result = getNext()(input, getNext);
public IEnumerable<Type> GetRequiredInterfaces()