Castle Windsor常用介绍以及其在ABP项目的应用介绍

本文介绍了Castle Windsor依赖注入框架如何在ABP框架中用于拦截包含特定属性的方法及实现IRepository和IApplicationService接口的对象。通过注册事件拦截,确保了单元工作模式下对指定方法的有效管理。


             return ;
         }
 
         //No current uow, run a new one
         PerformUow(invocation, unitOfWorkAttr.CreateOptions());
     }

它的注册是在模块中进行注册的,注册主要包含IRepository和IApplicationService和UnitOfWorkAttribute,所以包含[UnitOfWork]的方法和继承IRepository和IApplicationService的方法都会被拦截

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/// <summary>
/// 拦截注册事件
/// </summary>
/// <param name="key"></param>
/// <param name="handler"></param>
private  static  void  ComponentRegistered( string  key, IHandler handler)
{
     if  (UnitOfWorkHelper.IsConventionalUowClass(handler.ComponentModel.Implementation))
     {
         //Intercept all methods of all repositories.
         handler.ComponentModel.Interceptors.Add( new  InterceptorReference( typeof (UnitOfWorkInterceptor)));
     }
     else  if  (handler.ComponentModel.Implementation.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(UnitOfWorkHelper.HasUnitOfWorkAttribute))
     {
         //Intercept all methods of classes those have at least one method that has UnitOfWork attribute.
         //TODO: Intecept only UnitOfWork methods, not other methods!
         handler.ComponentModel.Interceptors.Add( new  InterceptorReference( typeof (UnitOfWorkInterceptor)));
     }
}

 

以上就把Castle Windsor的常用功能和ABP项目中的使用简单的讲完了。主要参考的几个项目ABP、NOP、Prodinner

简单的源码地址:http://pan.baidu.com/s/1kTCNpQZ

参考文章:

https://github.com/ABPFrameWorkGroup/AbpDocument2Chinese

https://github.com/castleproject/Windsor/blob/master/docs/README.md

http://www.cnblogs.com/wucg/archive/2012/03/09/2387946.html 

             return ;
         }
 
         //No current uow, run a new one
         PerformUow(invocation, unitOfWorkAttr.CreateOptions());
     }

它的注册是在模块中进行注册的,注册主要包含IRepository和IApplicationService和UnitOfWorkAttribute,所以包含[UnitOfWork]的方法和继承IRepository和IApplicationService的方法都会被拦截

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/// <summary>
/// 拦截注册事件
/// </summary>
/// <param name="key"></param>
/// <param name="handler"></param>
private  static  void  ComponentRegistered( string  key, IHandler handler)
{
     if  (UnitOfWorkHelper.IsConventionalUowClass(handler.ComponentModel.Implementation))
     {
         //Intercept all methods of all repositories.
         handler.ComponentModel.Interceptors.Add( new  InterceptorReference( typeof (UnitOfWorkInterceptor)));
     }
     else  if  (handler.ComponentModel.Implementation.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(UnitOfWorkHelper.HasUnitOfWorkAttribute))
     {
         //Intercept all methods of classes those have at least one method that has UnitOfWork attribute.
         //TODO: Intecept only UnitOfWork methods, not other methods!
         handler.ComponentModel.Interceptors.Add( new  InterceptorReference( typeof (UnitOfWorkInterceptor)));
     }
}

 

以上就把Castle Windsor的常用功能和ABP项目中的使用简单的讲完了。主要参考的几个项目ABP、NOP、Prodinner

简单的源码地址:http://pan.baidu.com/s/1kTCNpQZ

参考文章:

https://github.com/ABPFrameWorkGroup/AbpDocument2Chinese

https://github.com/castleproject/Windsor/blob/master/docs/README.md

http://www.cnblogs.com/wucg/archive/2012/03/09/2387946.html 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值