public static T CreateProxy <T>() where T : MarshalByRefObject { var instance = Activator.CreateInstance <T>(); var aopProxy = new AopProxy <T>(instance); aopProxy.BeforeExecute += (s, e) => Console.WriteLine($"Before Execute {e.MethodCallMessage.MethodName}"); aopProxy.AfterExecute += (s, e) => Console.WriteLine($"After Execute {e.MethodCallMessage.MethodName}"); aopProxy.ExecutionFailed += (s, e) => Console.WriteLine($"Execution failed {e.MethodCallMessage.MethodName}"); return(aopProxy.GetTransparentProxy() as T); }
public static IMyService CreateProxy <T>() where T : IMyService, new() { IMyService service = new T(); var aopProxy = new AopProxy <IMyService>(service); aopProxy.BeforeExecute += (s, e) => Console.WriteLine($"Before Execute {e.MethodCallMessage.MethodName}"); aopProxy.AfterExecute += (s, e) => Console.WriteLine($"After Execute {e.MethodCallMessage.MethodName}"); aopProxy.ExecutionFailed += (s, e) => Console.WriteLine($"Execution failed {e.MethodCallMessage.MethodName}"); return(aopProxy.GetTransparentProxy() as IMyService); }
public static IRepository <T> CreateProxy <T>() { var repository = new Repository <T>(); var aopProxy = new AopProxy <IRepository <T> >(repository); aopProxy.BeforeExecute += (s, e) => Console.WriteLine($"Before Execute {e.MethodCallMessage.MethodName}"); aopProxy.AfterExecute += (s, e) => Console.WriteLine($"After Execute {e.MethodCallMessage.MethodName}"); aopProxy.ExecutionFailed += (s, e) => Console.WriteLine($"Execution failed {e.MethodCallMessage.MethodName}"); return(aopProxy.GetTransparentProxy() as IRepository <T>); }