public void Intercept(IInvocation invocation) { MethodInfo method; try { method = invocation.MethodInvocationTarget; } catch { method = invocation.GetConcreteMethod(); } UnitOfWorkAttribute attribute = GetUnitOfWorkAttributeOrNull(method); if (attribute == null || attribute.IsDisabled) { //No need to a uow invocation.Proceed(); return; } //No current uow, run a new one PerformUow(invocation, attribute.CreateOptions()); }
private UnitOfWorkAttribute GetUnitOfWorkAttributeOrNull(MethodInfo methodInfo) { var attrs = methodInfo.GetCustomAttributes(true).OfType <UnitOfWorkAttribute>().ToArray(); if (attrs.Length > 0) { return(attrs[0]); } UnitOfWorkAttribute attr = methodInfo.DeclaringType.GetFirstAttribute <UnitOfWorkAttribute>(); return(attr); }