/// <summary> /// Determines whether [is unit of work method] [the specified method information]. /// </summary> /// <param name="methodInfo">The method information.</param> /// <param name="unitOfWorkAttribute">The unit of work attribute.</param> /// <returns><c>true</c> if [is unit of work method] [the specified method information]; otherwise, <c>false</c>.</returns> 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); }
/// <summary> /// Creates the options. /// </summary> /// <param name="invocation">The invocation.</param> /// <param name="unitOfWorkAttribute">The unit of work attribute.</param> /// <returns>UnitOfWorkOptions.</returns> private UnitOfWorkOptions CreateOptions(IMethodInvocation 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); }