/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork"/> class. /// </summary> /// <param name="dataSessionProvider">The data session provider.</param> /// <param name="activeDataSessionManager">The active data session manager.</param> /// <param name="flushMode">The flush mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="unitOfWorkBatchMode">The unit of work batch mode.</param> public UnitOfWork( IDataSessionProvider <ISession> dataSessionProvider, IActiveDataSessionManager <ISession> activeDataSessionManager, FlushMode flushMode = FlushMode.Auto, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, UnitOfWorkBatchMode unitOfWorkBatchMode = UnitOfWorkBatchMode.Singular) { this.dataSessionProvider = dataSessionProvider; this.activeDataSessionManager = activeDataSessionManager; this.flushMode = flushMode; this.isolationLevel = isolationLevel; this.UnitOfWorkBatchMode = unitOfWorkBatchMode; }
public void IncrementAndDecrementNestLevelWhenStartingMultipleUnitsOfWork(UnitOfWorkBatchMode unitOfWorkBatchMode) { // Arrange Bootstrapper.Start(); var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance <IUnitOfWorkFactory>(); unitOfWorkFactory.UnitOfWorkBatchMode = unitOfWorkBatchMode; var unitOfWork = unitOfWorkFactory.CreateUnitOfWork(); var repository = Bootstrapper.AmbientContainer.GetInstance <Repository <TestModel> >(); const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var testChildA = new TestChildModel("AAA"); var testChildB = new TestChildModel("BBB"); var testChildC = new TestChildModel("CCC"); var testModel = new TestModel(Key); testModel.TestChildren.Add(testChildA); testModel.TestChildren.Add(testChildB); testModel.TestChildren.Add(testChildC); using (unitOfWork.Start()) { repository.Create(testModel); unitOfWork.Commit(); } // Act & Assert using (unitOfWork.Start()) { Assert.That(unitOfWork.NestLevel.Equals(0)); this.ParentMethod(); Assert.That(unitOfWork.NestLevel.Equals(0)); unitOfWork.Commit(); } }
public void IncrementAndDecrementNestLevelWhenStartingMultipleUnitsOfWork(UnitOfWorkBatchMode unitOfWorkBatchMode) { // Arrange Bootstrapper.Start(); var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance<IUnitOfWorkFactory>(); unitOfWorkFactory.UnitOfWorkBatchMode = unitOfWorkBatchMode; var unitOfWork = unitOfWorkFactory.CreateUnitOfWork(); var repository = Bootstrapper.AmbientContainer.GetInstance<Repository<TestModel>>(); const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var testChildA = new TestChildModel("AAA"); var testChildB = new TestChildModel("BBB"); var testChildC = new TestChildModel("CCC"); var testModel = new TestModel(Key); testModel.TestChildren.Add(testChildA); testModel.TestChildren.Add(testChildB); testModel.TestChildren.Add(testChildC); using (unitOfWork.Start()) { repository.Create(testModel); unitOfWork.Commit(); } // Act & Assert using (unitOfWork.Start()) { Assert.That(unitOfWork.NestLevel.Equals(0)); this.ParentMethod(); Assert.That(unitOfWork.NestLevel.Equals(0)); unitOfWork.Commit(); } }
/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork"/> class. /// </summary> /// <param name="dataSessionProvider">The data session provider.</param> /// <param name="activeDataSessionManager">The active data session manager.</param> /// <param name="flushMode">The flush mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="unitOfWorkBatchMode">The unit of work batch mode.</param> public UnitOfWork( IDataSessionProvider<ISession> dataSessionProvider, IActiveDataSessionManager<ISession> activeDataSessionManager, FlushMode flushMode = FlushMode.Auto, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, UnitOfWorkBatchMode unitOfWorkBatchMode = UnitOfWorkBatchMode.Singular) { this.dataSessionProvider = dataSessionProvider; this.activeDataSessionManager = activeDataSessionManager; this.defaultFlushMode = flushMode; this.defaultIsolationLevel = isolationLevel; this.UnitOfWorkBatchMode = unitOfWorkBatchMode; }
/// <summary> /// Creates a new Unit of Work. /// </summary> /// <param name="flushMode">The flush mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="unitOfWorkBatchMode">The unit of work batch mode.</param> /// <returns> /// A new Unit of Work. /// </returns> public IUnitOfWork CreateUnitOfWork(FlushMode flushMode, IsolationLevel isolationLevel, UnitOfWorkBatchMode unitOfWorkBatchMode) { return(new UnitOfWork(dataSessionProvider, activeDataSessionManager, flushMode, isolationLevel, unitOfWorkBatchMode)); }