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 = "" };
userprocessor.RegUser(user);
}
catch (Exception ex)
{
throw ex;
}
上一篇:React Native中的约束规范


下一篇:JVM(9)之 年轻代收集器