예제 #1
0
        public static bool IsUnitOfWorkMethod([NotNull] MethodInfo methodInfo, [CanBeNull] out UnitOfWorkAttribute unitOfWorkAttribute)
        {
            Check.NotNull(methodInfo, nameof(methodInfo));

            //获取方法的Attributes
            var attrs = methodInfo.GetCustomAttributes(true).OfType <UnitOfWorkAttribute> ().ToArray();

            if (attrs.Any())
            {
                unitOfWorkAttribute = attrs.First();
                return(!unitOfWorkAttribute.IsDisabled);
            }

            if (methodInfo.DeclaringType != null)
            {
                //判断类是否显示定义UnitOfWorkAttribute
                attrs = methodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true).OfType <UnitOfWorkAttribute> ().ToArray();
                if (attrs.Any())
                {
                    unitOfWorkAttribute = attrs.First();
                    return(!unitOfWorkAttribute.IsDisabled);
                }

                //判断类是否继承接口IUnitOfWorkEnabled
                if (typeof(IUnitOfWorkEnabled).GetTypeInfo().IsAssignableFrom(methodInfo.DeclaringType))
                {
                    unitOfWorkAttribute = null;
                    return(true);
                }
            }

            unitOfWorkAttribute = null;
            return(false);
        }
예제 #2
0
        private RocketUnitOfWorkOptions CreateOptions(IRocketMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new RocketUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                options.IsTransactional = _defaultOptions.CalculateIsTransactional(
                    autoValue: !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase)
                    );
            }

            return(options);
        }