Пример #1
0
        public UnitOfWorkTransactionScope(UnitOfWorkScopeOption joiningOption, bool readOnly, IsolationLevel?isolationLevel, IDbContextFactoryProducerSingleton dbContextFactory = null, IAmbientDbContextLocator contextLocator = null, IGenericRepositoryFactory repositoryFactory = null, IDomainEvents domainEvents = null, CancellationToken cancellationToken = default(CancellationToken))
            : base(contextLocator : contextLocator, repositoryFactory : repositoryFactory, cancellationToken : cancellationToken)
        {
            if (isolationLevel.HasValue && joiningOption == UnitOfWorkScopeOption.JoinExisting)
            {
                throw new ArgumentException("Cannot join an ambient UnitOfWorkScope when an explicit database transaction is required. When requiring explicit database transactions to be used (i.e. when the 'isolationLevel' parameter is set), you must not also ask to join the ambient context (i.e. the 'joinAmbient' parameter must be set to false).");
            }

            _disposed  = false;
            _completed = false;
            _readOnly  = readOnly;

            _parentScope = GetAmbientScope();
            if (_parentScope != null && joiningOption == UnitOfWorkScopeOption.JoinExisting)
            {
                if (_parentScope._readOnly && !this._readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write UnitOfWorkScope within a read-only UnitOfWorkScope.");
                }

                _nested     = true;
                _dbContexts = _parentScope._dbContexts;
            }
            else
            {
                _nested     = false;
                _dbContexts = new DbContextCollection(readOnly, isolationLevel, dbContextFactory, domainEvents);
            }

            SetAmbientScope(this);
        }
Пример #2
0
 public TransactionScope(DbContext context, UnitOfWorkScopeOption scopeOption = UnitOfWorkScopeOption.Required,
                         IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
 {
     _context        = context ?? throw new ArgumentNullException(nameof(context));
     _scopeOption    = scopeOption;
     _isolationLevel = isolationLevel;
     _connection     = _context.Database.GetDbConnection();
 }
Пример #3
0
 public IUnitOfWorkReadOnlyScope CreateReadOnly(UnitOfWorkScopeOption joiningOption = UnitOfWorkScopeOption.JoinExisting)
 {
     return(new UnitOfWorkReadOnlyScope(
                joiningOption: joiningOption,
                isolationLevel: null,
                dbContextFactory: _dbContextFactory,
                contextLocator: _contextLocator,
                repositoryFactory: _repositoryFactory));
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWork{TContext}"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public UnitOfWork(TContext context, UnitOfWorkScopeOption scopeOption = UnitOfWorkScopeOption.Required,
                   System.Data.IsolationLevel isolationLevel           = System.Data.IsolationLevel.ReadCommitted)
 {
     _context        = context ?? throw new ArgumentNullException(nameof(context));
     _current        = this;
     _connection     = _context.Database.GetDbConnection();
     _scopeOption    = scopeOption;
     _isolationLevel = isolationLevel;
 }
 /// <summary>
 /// ProvideForCompany
 /// </summary>
 /// <param name="scopeOption">scopeOption</param>
 /// <param name="isolationLevel">isolationLevel</param>
 /// <returns></returns>
 protected IUnitOfWork Provide(UnitOfWorkScopeOption scopeOption = UnitOfWorkScopeOption.Required,
                               IsolationLevel isolationLevel     = IsolationLevel.ReadCommitted)
 {
     return(Provider.Provide(scopeOption, isolationLevel));
 }
 public UnitOfWorkReadOnlyScope(UnitOfWorkScopeOption joiningOption, IsolationLevel?isolationLevel, IDbContextFactoryProducerSingleton dbContextFactory = null, IAmbientDbContextLocator contextLocator = null, IGenericRepositoryFactory repositoryFactory = null)
     : base(contextLocator : contextLocator, repositoryFactory : repositoryFactory)
 {
     _internalScope = new UnitOfWorkTransactionScope(joiningOption : joiningOption, readOnly : true, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory, contextLocator : contextLocator, repositoryFactory : repositoryFactory);
 }