Example #1
0
        public void TestCustomerCreation()
        {
            //Creating customer

            var Customer = new Customer() { CustomerName = "Customer 1", Telephome = "78-676-121212", Sites = new List<Site>() };
            Customer.Sites.Add(new Site() { Address = "Site 1", PostCode = "001", SiteNumber = "ST01" });
            Customer.Sites.Add(new Site() { Address = "Site 2", PostCode = "002", SiteNumber = "ST02" });

            iocCtxFactory = iocContainer.Resolve<IDbContextFactory>();
            var iocDBContext = iocCtxFactory.GetContext();

            //adding customer to database
            var sotredCustomer = iocDBContext.Set<Customer>().Add(Customer);
            iocDBContext.SaveChanges();
            var customerId = sotredCustomer.Id;

            //Test
            var nonIoCContext = new DbContextFactory().GetContext();

            var customerFrom_IOC_Context = iocCtxFactory.GetContext().Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault();

            var customerNon_IOC_Context = nonIoCContext.Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault();

            Assert.IsNull(customerNon_IOC_Context.Sites);

            //Expecting empty but having values if IOC lifestyle is singleton or PerWebRequest :(
            //transient is working as expected
            Assert.IsNull(customerFrom_IOC_Context.Sites);
        }
        public ScheduleUnitOfWorkFactory(IDbContextFactory<ScheduleContext> contextFactory)
        {
            if (contextFactory == null)
                throw new ArgumentNullException(nameof(contextFactory));

            _contextFactory = contextFactory;
        }
 public DbContextBuilder(IDbContextFactory factory, IInterceptorsResolver interceptorsResolver, IRepository repository, IDbContextUtilities contextUtilities)
 {
     this.factory = factory;
     this.interceptorsResolver = interceptorsResolver;
     this.repository = repository;
     this.contextUtilities = contextUtilities;
 }
 public DbContextReadOnlyScope(IDbContextFactory dbContextFactory = null)
     : this(
         joiningOption: DbContextScopeOption.JoinExisting,
         isolationLevel: null,
         dbContextFactory: dbContextFactory)
 {
 }
 public DbContextReadOnlyScope(IsolationLevel isolationLevel, IDbContextFactory dbContextFactory = null)
     : this(
         joiningOption: DbContextScopeOption.ForceCreateNew,
         isolationLevel: isolationLevel,
         dbContextFactory: dbContextFactory)
 {
 }
Example #6
0
        public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel? isolationLevel, IDbContextFactory dbContextFactory = null)
        {
            if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting)
                throw new ArgumentException("Cannot join an ambient DbContextScope 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 == DbContextScopeOption.JoinExisting)
            {
                if (_parentScope._readOnly && !this._readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope.");
                }

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

            SetAmbientScope(this);
        }
Example #7
0
 public OrderSaver(IDbContextFactory contextFactory,
                   IEntitySaver entitySaver,
                   IShipmentOrderItemsUpdater shipmentOrderItemsUpdater)
 {
     _contextFactory = contextFactory;
     _entitySaver = entitySaver;
     _shipmentOrderItemsUpdater = shipmentOrderItemsUpdater;
 }
        public DefaultRepositoryConfigurationSettings(IDbContextFactory dbContextFactory)
        {
            DbContextFactory = dbContextFactory ?? Create.New<IDbContextFactory>();

            ShouldValidate = true;
            ShouldWrapInTransaction = true;
            ShouldIncludeDependencies = false;
            ShouldTrackEntities = false;
        }
Example #9
0
        /// <summary>
        ///     Инициализирует новый экземпляр класса <see cref="UnitOfWorkEf" />
        /// </summary>
        /// <param name="contextFactory">Фабрика контекста доступа к БД</param>
        /// <param name="isolationLevel">Уровень изоляции данных</param>
        public UnitOfWorkEf(
            IDbContextFactory contextFactory,
            IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
        {
            this._context = contextFactory.CreateDbContext<EntitiesContext>();

            // Если БД не была создана вызовет ошибку
            this._transaction = this._context.Database.BeginTransaction(isolationLevel);
        }
Example #10
0
        public MusicStoreUnitOfWork(IDbContextFactory contextFactory)
        {
            if (contextFactory == null)
            {
                throw new ArgumentNullException("contextFactory");
            }

            _contextFactory = contextFactory;
        }
        public EntityFrameworkUnitOfWorkFactory(IConfiguration configuration, IDbContextFactory contextFactory, IDbConfiguration dbConfiguration)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (contextFactory == null) throw new ArgumentNullException("contextFactory");
            if (dbConfiguration == null) throw new ArgumentNullException("dbConfiguration");

            _configuration = configuration;
            _contextFactory = contextFactory;
            _dbConfiguration = dbConfiguration;
            _contextType = null;
        }
 public SetupGameStuff(IDbContextLocator locator, IDbContextFactory factory,
     INetworkContentSyncer networkContentSyncer, /* ICacheManager cacheMan, */
     IGameLocker gameLocker, IStateHandler stateHandler, IAssemblyService ass) {
     _locator = locator;
     _factory = factory;
     _networkContentSyncer = networkContentSyncer;
     //_cacheMan = cacheMan;
     _gameLocker = gameLocker;
     _stateHandler = stateHandler;
     _timer = new TimerWithElapsedCancellationAsync(TimeSpan.FromMinutes(30), onElapsedNonBool: OnElapsed);
     _gameFactory = new GameFactory(ass);
 }
Example #13
0
        public EventLogger(IDbContextFactory dbContextFactory)
        {
            var dbContext = dbContextFactory.GetContext();
            _dbPackageEventSet = dbContext.Set<PackageEvent>();
            _dbSchedulerEventSet = dbContext.Set<SchedulerEvent>();
            _dbServerEventSet = dbContext.Set<ServerEvent>();
            _dbSystemEventSet = dbContext.Set<SystemEvent>();
            _dbServerDeploymentEventSet = dbContext.Set<ServerDeploymentEvent>();
            _dbNotificationSet = dbContext.Set<Notification>();
            _dbNotificationTypeSet = dbContext.Set<NotificationType>();

            intNotificationTypeID = FindNotificationType("MindAlign");
        }
        public EntityFrameworkUnitOfWorkFactory(
            IConfiguration configuration,
            IDbContextFactory contextFactory,
            IDbConfiguration dbConfiguration,
            IEntityFrameworkRepositoryLogger logger) : this(logger)
        {
            if (configuration == null) throw new ArgumentNullException(nameof(configuration));
            if (contextFactory == null) throw new ArgumentNullException(nameof(contextFactory));
            if (dbConfiguration == null) throw new ArgumentNullException(nameof(dbConfiguration));

            _configuration = configuration;
            _contextFactory = contextFactory;
            _dbConfiguration = dbConfiguration;
            _contextType = null;
        }
 private static DbContextContainer GetCurrentDbContext(IDbContextFactory factory)
 {
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     if (factory.DbContextContainer == null)
     {
         throw new Exception("没有配置CurrentDbContext");
     }
     DbContextContainer currentDbContext = factory.DbContextContainer as DbContextContainer;
     if (currentDbContext == null)
     {
         throw new Exception("Current DbContext没有继承CurrentDbContext");
     }
     return currentDbContext;
 }
Example #16
0
      /// <exception cref="ArgumentNullException">
      /// <paramref name="serverImagesPath"/> or
      /// <paramref name="archiveDirectoryPath"/> or
      /// <paramref name="contextFactory"/> or
      /// <paramref name="dateTimeProxy"/> or
      /// <paramref name="activatorProxy"/> is <see langword="null" />.</exception>
      internal UpdateService(string serverImagesPath, string archiveDirectoryPath, IDbContextFactory<UpdateDbContext> contextFactory,
         IDateTimeProxy dateTimeProxy, IActivatorProxy activatorProxy)
      {
         if (serverImagesPath == null)
            throw new ArgumentNullException("serverImagesPath");

         if (archiveDirectoryPath == null)
            throw new ArgumentNullException("archiveDirectoryPath");

         if (contextFactory == null)
            throw new ArgumentNullException("contextFactory");

         if (dateTimeProxy == null)
            throw new ArgumentNullException("dateTimeProxy");

         if (activatorProxy == null)
            throw new ArgumentNullException("activatorProxy");

         _serverImagesPath = serverImagesPath;
         _archiveDirectoryPath = archiveDirectoryPath;
         _contextFactory = contextFactory;
         _dateTimeProxy = dateTimeProxy;
         _activatorProxy = activatorProxy;
      }
Example #17
0
 private EmployersRepositoryService NewService(IDbContextFactory <IEmployersContext> employersContextFactory = null)
 {
     return(new EmployersRepositoryService(employersContextFactory));
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryRepository"/> class.
 /// </summary>
 /// <param name="dbContextFactory">The database context factory.</param>
 public QueryRepository(IDbContextFactory dbContextFactory)
 {
     this.dbContextFactory = dbContextFactory;
 }
Example #19
0
 public DealDocumentScansController(IDbContextFactory factory)
 {
     this.factory   = factory;
     identityHelper = new IdentityHelper();
     request        = new Request();
 }
Example #20
0
 public UsersController()
 {
     this.contextFactory = new SocialLifeDbContextFactory();
 }
Example #21
0
 public BookRepository(IDbContextFactory <PanXPanDbContext> contextFactory)
 {
     _contextFactory = contextFactory;
 }
Example #22
0
 public HierarchyRepository(IDbContextFactory <MarkdownEfContext> contextFactory) : base(contextFactory)
 {
 }
 public CharacterService(IDbContextFactory <DatabaseContext> dbContextFactory)
 {
     _dbContextFactory = dbContextFactory;
 }
 public DbContextScopeFactory(IDbContextFactory dbContextFactory)
 {
     _dbContextFactory = dbContextFactory;
 }
Example #25
0
 public MarkingPeriodRepository(IDbContextFactory dbContextFactory)
 {
     this.context = dbContextFactory.Create();
 }
 public RadioProfileRepository(IDbContextFactory <ApplicationDbContext> contextFactory) : base(contextFactory)
 {
 }
 public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null)
 {
     _internalScope = new DbContextScope(joiningOption : joiningOption, readOnly : true, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory);
 }
 public DbContextReadOnlyScope(IsolationLevel isolationLevel, IDbContextFactory dbContextFactory = null)
     : this(joiningOption : DbContextScopeOption.ForceCreateNew, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory)
 {
 }
Example #29
0
 public SongDifficultyByIdDataLoader(IBatchScheduler batchScheduler, IDbContextFactory <DatabaseContext> dbContextFactory) : base(batchScheduler)
 {
     _dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
 }
Example #30
0
 public ConcertRepository(IDbContextFactory dbContextFactory) : base(dbContextFactory)
 {
 }
 public MyBlogApiServerSide(IDbContextFactory <MyBlogDbContext> factory)
 {
     this.factory = factory;
 }
 public ReportsRepository(IDbContextFactory dbContextFactory) : base(dbContextFactory)
 {
 }
Example #33
0
 public UsersController(IDbContextFactory <DbContext> contextFactory)
 {
     this.contextFactory = contextFactory;
 }
 public CountryContext(IDbContextFactory dbContextFactory)
 {
     _dbContext = dbContextFactory.GetDbContext();
 }
Example #35
0
 public DealDocumentScansController(IDbContextFactory factory, IIdentityHelper identityHelper, IRequest request)
 {
     this.factory        = factory;
     this.identityHelper = identityHelper;
     this.request        = request;
 }
 public void BeforeTest()
 {
     Database.SetInitializer(new DropCreateDatabaseAlways<EasyReadDbContext>());
     _contextFactory = new TestContextFactory(new EasyReadDbContext("DefaultContext"));
     _contextFactory.GetContext().Database.Initialize(true);
 }
Example #37
0
 public DealDocumentScansController()
 {
     factory        = new DbContextFactory();
     identityHelper = new IdentityHelper();
     request        = new Request();
 }
Example #38
0
 public SqlIdnConsentStore(IDbContextFactory<SqlIdnDbContext> dbContextFactory)
 {
     Raise.ArgumentNullException.IfIsNull(dbContextFactory, nameof(dbContextFactory));
     _dbContextFactory = dbContextFactory;
 }
 public ApplicationClaimsTransformation(IDbContextFactory <ModulesDbContext> factory, ContentService contentService)
 {
     Factory        = factory;
     ContentService = contentService;
 }
 public PostsController(IDbContextFactory<DbContext> contextFactory)
 {
     this.contextFactory = contextFactory;
 }
Example #41
0
 public GateHandler(Options features, GateRepository repository, IDbContextFactory <CharacterContext> characterFactory)
 {
     _features         = features;
     _repository       = repository;
     _characterFactory = characterFactory;
 }
Example #42
0
 public UnitOfWork(IDbContextFactory contextFactory)
 {
     _contextFactory = contextFactory;
 }
Example #43
0
        public BrokerRepository(
			IDbContextFactory<ITmsDatabaseContext> tmsDbContextFactory)
        {
            _tmsDbContextFactory = tmsDbContextFactory;
        }
Example #44
0
 public void TestInitialize()
 {
     _dbContextFactory = new DataAccessorContextFactory();
 }
 public DbContextScope(bool readOnly, IDbContextFactory dbContextFactory = null)
     : this(joiningOption : DbContextScopeOption.JoinExisting, readOnly : readOnly, isolationLevel : null, dbContextFactory : dbContextFactory)
 {
 }
Example #46
0
 public UserContext(IDbContextFactory dbContextFactory)
 {
     _dbContext = dbContextFactory.GetDbContext();
 }
 public UsersController(IDbContextFactory<DbContext> contextFactory)
     : base(contextFactory)
 {
 }
        public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null)
        {
            if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting)
            {
                throw new ArgumentException("Cannot join an ambient DbContextScope 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 == DbContextScopeOption.JoinExisting)
            {
                if (_parentScope._readOnly && !this._readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope.");
                }

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

            SetAmbientScope(this);
        }
 public DatabaseCommunicator(IDbToolConfig config, IDbContextFactory dbConnectionFactory)
 {
     _config = config;
     _dbConnectionFactory = dbConnectionFactory;
 }
Example #50
0
 public SIPCallDataLayer(IDbContextFactory <SIPAssetsDbContext> dbContextFactory)
 {
     _dbContextFactory = dbContextFactory;
 }
 public PostsController()
 {
     this.contextFactory = new DbForumContextFactory();
 }
Example #52
0
 public WebPushController(WebPushService pushService, IDbContextFactory <TempsDbContext> dbContext)
 {
     _wp = pushService;
     _db = dbContext;
 }
Example #53
0
 public HomeController(IDbContextFactory contextFactory, ICacheStorage<string> cacheStorage, ILogger logger)
     : base(contextFactory, cacheStorage, logger)
 {
 }
Example #54
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmployeeDeductionRepository"/> class.
 /// </summary>
 /// <param name="dbContextFactory">The database context factory.</param>
 public EmployeeDeductionRepository(IDbContextFactory dbContextFactory)
 {
     this.dbContextFactory = dbContextFactory ?? new DbContextFactory(null);;
 }
Example #55
0
 public PostContext(IDbContextFactory dbContextFactory)
 {
     _dbContext = dbContextFactory.GetDbContext();
 }
Example #56
0
 public ManageUsers(IDbContextFactory <ApplicationDbContext> dbFactory)
 {
     _dbFactory = dbFactory;
 }
Example #57
0
 public StoresController(IDbContextFactory<DbContext> contextFactory)
     : base(contextFactory)
 {
 }
Example #58
0
 public CourseService(IDbContextFactory <EFContext> dbContextFactory) : base(dbContextFactory)
 {
     this.dbContextFactory = dbContextFactory;
 }
Example #59
0
 public UserService(IDbContextFactory<AccountingContext> contextFactory)
 {
     this.contextFactory = contextFactory;
 }
Example #60
0
 public AppFacade(IDbContextFactory dbContextFactory, IMapper mapper)
 {
     _dbContextFactory = dbContextFactory;
     _mapper           = mapper;
 }