public IUnitOfWork CreateNew(ScopeType scopeType) { ThrowIfUnknownScopeType(scopeType); ScopedUnitOfWorkConfiguration.LoggingAction("[ScopeManager] new unit of work requested with " + scopeType); // in case there were no units of work before or the ones that existed completely ended and self-destructed CreateNewStackIfNoneExist(); var newUnitOfWork = CreateUnitOfWork(scopeType); ScopeStack.Stack.Push(newUnitOfWork); if (scopeType == ScopeType.Transactional && !ScopeStack.HasTransaction()) { ScopedUnitOfWorkConfiguration.LoggingAction("[ScopeManager] creating and setting a new transaction"); ScopeStack.SetTransaction(CreateAndStartTransaction()); } return(newUnitOfWork); }