Exemple #1
0
 public UnitOfWorkScopeFactory(IDbContextFactoryProducerSingleton dbContextFactory = null, IAmbientDbContextLocator contextLocator = null, IGenericRepositoryFactory repositoryFactory = null, IDomainEvents domainEvents = null)
 {
     _dbContextFactory  = dbContextFactory;
     _contextLocator    = contextLocator;
     _repositoryFactory = repositoryFactory;
     _domainEvents      = domainEvents;
 }
        public void SetUp()
        {
            var config = new MapperConfiguration(cfg =>
            {
            });

            _mapper = config.CreateMapper();

            var connectionString = TestHelper.GetConfiguration("Integration").GetConnectionString("DefaultConnection");

            _context = TestHelper.GetContext <ApplicationContext>(connectionString, false);

            var mockUserService = new Mock <IUserService>();

            var mockAuthorizationService = new Mock <IAuthorizationService>();

            var mockDbContextFactory = new Mock <IDbContextFactory <ApplicationContext> >();

            mockDbContextFactory.Setup(c => c.CreateDbContext()).Returns(_context);

            var mockDbContextFactoryProducer = new Mock <IDbContextFactoryProducerSingleton>();

            mockDbContextFactoryProducer.Setup(c => c.GetFactory <ApplicationContext>()).Returns(mockDbContextFactory.Object);
            _dbContextFactoryProducer = mockDbContextFactoryProducer.Object;

            _identityContext = TestHelper.GetContext <IdentityContext>(connectionString, false);

            _controller = new FlightSearchController(new FlightSearchApplicationService(new FlightSearchDomainService(new UnitOfWorkScopeFactory(_dbContextFactoryProducer, new AmbientDbContextLocator(), new GenericRepositoryFactory())), _mapper, mockAuthorizationService.Object, mockUserService.Object), _mapper, null, null, null, mockAuthorizationService.Object);
        }
Exemple #3
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);
        }
Exemple #4
0
 public UnitOfWorkTransactionScope(bool readOnly, IDbContextFactoryProducerSingleton dbContextFactory = null, IAmbientDbContextLocator contextLocator = null, IGenericRepositoryFactory repositoryFactory = null, IDomainEvents domainEvents = null, CancellationToken cancellationToken = default(CancellationToken))
     : this(joiningOption : UnitOfWorkScopeOption.JoinExisting, readOnly : readOnly, isolationLevel : null, dbContextFactory : dbContextFactory, contextLocator : contextLocator, repositoryFactory : repositoryFactory, cancellationToken : cancellationToken)
 {
 }
 public ApplicationContextInitializer(IDbContextFactoryProducerSingleton dbContextFactory, IHostingEnvironment hostingEnvironment)
 {
     _dbContextFactory   = dbContextFactory;
     _hostingEnvironment = hostingEnvironment;
 }
 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);
 }
 public UnitOfWorkReadOnlyScope(IsolationLevel isolationLevel, IDbContextFactoryProducerSingleton dbContextFactory = null, IAmbientDbContextLocator contextLocator = null, IGenericRepositoryFactory repositoryFactory = null)
     : this(joiningOption : UnitOfWorkScopeOption.ForceCreateNew, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory)
 {
 }
Exemple #8
0
 public DynamicFormsContextInitializer(IDbContextFactoryProducerSingleton dbContextFactory, IHostingEnvironment hostingEnvironment)
 {
     _dbContextFactory   = dbContextFactory;
     _hostingEnvironment = hostingEnvironment;
 }