Net AOP(五) 各种IoC框架下实现AOP
public interface IUserProcessor { void RegUser(User user); } public class UserProcessor : IUserProcessor { public virtual void RegUser(User user) { Console.WriteLine("用户已注册。Name:{0},PassWord:{1}", user.Name, user.PassWord); } } public class MyInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { PreProceed(invocation); invocation.Proceed(); PostProceed(invocation); } public void PreProceed(IInvocation invocation) { Console.WriteLine("方法执行前"); } public void PostProceed(IInvocation invocation) { Console.WriteLine("方法执行后"); } } public class User { public string Name { get; set; } public string PassWord { get; set; } } try { ProxyGenerator generator = new ProxyGenerator(); MyInterceptor interceptor = new MyInterceptor(); UserProcessor userprocessor = generator.CreateClassProxy<UserProcessor>(interceptor); User user = new User() { Name = "lee", PassWord = "123123123123" }; userprocessor.RegUser(user); } catch (Exception ex) { throw ex; }
posted on 2017-06-21 15:52 HOT SUMMER 阅读(162) 评论(0) 编辑 收藏 举报