protected void Init() { //线程中是否存在栈,如果存在栈,则当前事务为嵌套事务,否则为最外层事务; if (UnitOfWorkStackManager.ThreadBoundUnitOfWorkStackExists) { IsOuterMostUnitOfWork = false; Logger.Debug(m => m("[AbstractUnitOfWork.Init]:the initiates UnitOfWork is Nested UnitOfWork,Inner(deepth:{0})", UnitOfWorkStackManager.Count + 1)); } else { IsOuterMostUnitOfWork = true; Logger.Debug(m => m("[AbstractUnitOfWork.Init]:the initiates UnitOfWork is OutMost UnitOfWork.")); } //把当前UnitOfWork压入栈中 UnitOfWorkStackManager.Push(this); }
/// <summary> /// Dispose /// </summary> public virtual void Dispose() { //验证栈的最顶部的IUnitOfWork是否是当前IUnitOfWork.如果不是,抛出异常。 AssertUtils.State(this == UnitOfWorkStackManager.Pop(), "[AbstractUnitOfWork.Dispose]:Disposing UnitOfWork must on top of the ThreadBoundedStack."); }