public static bool IsUnitOfWorkMethod([NotNull] MethodInfo methodInfo, [CanBeNull] out UnitOfWorkAttribute unitOfWorkAttribute) { Check.NotNull(methodInfo, nameof(methodInfo)); //Method declaration var attrs = methodInfo.GetCustomAttributes(true).OfType <UnitOfWorkAttribute>().ToArray(); if (attrs.Any()) { unitOfWorkAttribute = attrs.First(); return(!unitOfWorkAttribute.IsDisabled); } if (methodInfo.DeclaringType != null) { //Class declaration attrs = methodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true).OfType <UnitOfWorkAttribute>().ToArray(); if (attrs.Any()) { unitOfWorkAttribute = attrs.First(); return(!unitOfWorkAttribute.IsDisabled); } //Conventional classes if (typeof(IUnitOfWorkEnabled).GetTypeInfo().IsAssignableFrom(methodInfo.DeclaringType)) { unitOfWorkAttribute = null; return(true); } } unitOfWorkAttribute = null; return(false); }
private UnitOfWorkOptions CreateOptions(IQfMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute) { var options = new UnitOfWorkOptions(); unitOfWorkAttribute?.SetOptions(options); if (unitOfWorkAttribute?.IsTransactional == null) { options.IsTransactional = _defaultOptions.CalculateIsTransactional( autoValue: !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase) ); } return(options); }