я этот кодединства - intecepting класса вызовов с несколькими интерфейсами
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);
}
}
я хочу использовать единства для перехвата всех вызовов функций, чтобы проверить, сколько времени потребуется для каждого вызова.
мой основной код
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>();
но решимостью я получаю исключение, что тип не interceptable
я добавил эту линию уаг IntP = container.Configure <Перехват>() SetInterceptorFor (TypeOf (Multi), новый TransparentProxyInterceptor()); и получил исключение -> Тип ConsoleApplication1.Multi не является перехваченным. Имя параметра: typeToIntercept –
Добавьте «MarshalByRefObject» в класс Multi. – code4life
Что такое MarshalByRefObject? –