Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
 /// <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));
 }