.Net常见的IOC框架及AOP框架
2021-05-08 08:27
标签:proc RoCE specific net开发 编程 user repr cts col .Net常见的IOC框架及AOP框架 标签:proc RoCE specific net开发 编程 user repr cts col 原文地址:https://www.cnblogs.com/zhaoshujie/p/12080569.htmlIOC框架
AOP框架
一个Castle的实现
//首先下载Castle.Windsor.dll
//自定义Interceptor
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 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 Client
{
public static void Run()
{
try
{
ProxyGenerator generator = new ProxyGenerator();
MyInterceptor interceptor = new MyInterceptor();
UserProcessor userprocessor = generator.CreateClassProxy
文章标题:.Net常见的IOC框架及AOP框架
文章链接:http://soscw.com/index.php/essay/83984.html