1
我有這樣的代碼團結 - 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>();
,但在解決我得到異常的類型不是截取的
我已經加入此線無功INTP = container.Configure <攔截>()SetInterceptorFor(typeof運算(多),新TransparentProxyInterceptor() );並得到異常 - >類型ConsoleApplication1.Multi不可攔截。 參數名稱:typeToIntercept – 2012-03-22 21:09:23
將'MarshalByRefObject'添加到Multi類。 – code4life 2012-03-22 21:22:40
什麼是MarshalByRefObject? – 2012-03-22 21:52:02