Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new <see cref="MaijeRepository{TEntity, TIdentifier}"/>
        /// </summary>
        /// <param name="databaseContext">The database context</param>
        public MaijeRepository(IMaijeDbContext databaseContext, IPaginationDomainService paginationDomainService)
        {
            _paginationDomainService = paginationDomainService ?? throw new ArgumentNullException(nameof(paginationDomainService));

            if (databaseContext == null)
            {
                throw new ArgumentNullException(nameof(databaseContext));
            }

            // We don't give access to the data context to prevent usage of SaveChanges() and other stuff
            // So we only store DbSet
            DbSet = databaseContext.Set <TEntity>() as DbSet <TEntity>; // Ugly cast, maybe wa can find a better way

            if (DbSet == null)
            {
                throw new InfrastructureException($"The {nameof(databaseContext)} must be a MaijeDbContext to work with repository.");
            }
        }