/// <summary> /// Gets UnitOfWorkAttribute for given method or null if no attribute defined. /// </summary> /// <param name="methodInfo">Method to get attribute</param> /// <returns>The UnitOfWorkAttribute object</returns> internal static UnitOfWorkAttribute GetUnitOfWorkAttributeOrNull(MemberInfo methodInfo) { var attrs = methodInfo.GetCustomAttributes(typeof(UnitOfWorkAttribute), false); if (attrs.Length > 0) { return((UnitOfWorkAttribute)attrs[0]); } return(UnitOfWorkHelper.IsConventionalUowClass(methodInfo.DeclaringType) ? new UnitOfWorkAttribute() : null); }
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. handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); } }