i have this code
public interface Interfcae1
{
void OP1();
}
public interface Interfcae2
{
void OP2();
}
public interface Interfcae3
{
void OP3();
}
public class Multi : Interfcae1, Interfcae2, Interfcae3
{
public void OP1()
{
System.Threading.Thread.Sleep(500);
}
public void OP2()
{
System.Threading.Thread.Sleep(1500);
}
public void OP3()
{
System.Threading.Thread.Sleep(2500);
}
}
i want to use unity to intercept all the function calls to test how much time it take for each call.
my main code is
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<Interfcae1, Multi>(
// new InjectionConstructor(typeof(string)),
new Interceptor<TransparentProxyInterceptor>(),
new InterceptionBehavior<InterceptBehavior>());
container.RegisterType<Interfcae2, Multi>(
// new InjectionConstructor(typeof(string)),
new Interceptor<TransparentProxyInterceptor>(),
new InterceptionBehavior<InterceptBehavior>());
container.RegisterType<Interfcae2, Multi>(
// new InjectionConstructor(typeof(string)),
new Interceptor<TransparentProxyInterceptor>(),
new InterceptionBehavior<InterceptBehavior>());
var proxy = container.Resolve<Multi>();
but at the resolve i am getting exception that the type is not interceptable
Did you remember to
Configure?After that, do an
AddPolicyand you should be good to go… Remember to specify the type info for the interface to intercept, and the interception handler.Also try modifying the
Multiclass definition as: