初始化入口
在AbpKernelModule类中,通过UnitOfWorkRegistrar.Initialize(IocManager) 方法去初始化
1 /// <summary> 2 /// This class is used to register interceptor for needed classes for Unit Of Work mechanism. 3 /// </summary> 4 internal static class UnitOfWorkRegistrar 5 { 6 /// <summary> 7 /// Initializes the registerer. 8 /// </summary> 9 /// <param name="iocManager">IOC manager</param> 10 public static void Initialize(IIocManager iocManager) 11 { 12 iocManager.IocContainer.Kernel.ComponentRegistered += ComponentRegistered; 13 } 14 15 private static void ComponentRegistered(string key, IHandler handler) 16 { 17 if (UnitOfWorkHelper.IsConventionalUowClass(handler.ComponentModel.Implementation)) 18 { 19 //Intercept all methods of all repositories. 20 handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); 21 } 22 else if (handler.ComponentModel.Implementation.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(UnitOfWorkHelper.HasUnitOfWorkAttribute)) 23 { 24 //Intercept all methods of classes those have at least one method that has UnitOfWork attribute. 25 //TODO: Intecept only UnitOfWork methods, not other methods! 26 handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); 27 } 28 } 29 }