Exemplo n.º 1
0
 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)));
     }
 }
        /// <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(true).OfType <UnitOfWorkAttribute>().ToArray();

            if (attrs.Length > 0)
            {
                return(attrs[0]);
            }

            if (UnitOfWorkHelper.IsConventionalUowClass(methodInfo.DeclaringType))
            {
                return(new UnitOfWorkAttribute()); //Default
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <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 GetUnitOfWorkAttributeOrDefault(MemberInfo methodInfo)
        {
            var attrs = methodInfo.GetCustomAttributes(typeof(UnitOfWorkAttribute), false);

            if (attrs.Length > 0)
            {
                return((UnitOfWorkAttribute)attrs[0]);
            }

            if (UnitOfWorkHelper.IsConventionalUowClass(methodInfo.DeclaringType))
            {
                return(new UnitOfWorkAttribute()); //Default
            }

            return(null);
        }