Ejemplo n.º 1
0
        public IBaseRepositoryAsync <TEntity> GetRepositoryForEntity <TEntity>() where TEntity : class, IBaseEntity, new()
        {
            _repositoryCache.TryGetValue(typeof(IBaseRepositoryAsync <TEntity>), out var repoObject);
            if (repoObject != null)
            {
                return((IBaseRepositoryAsync <TEntity>)repoObject);
            }
            //Repo not found in cache, post it

            var repoCreationMethod = _repositoryFactory.GetRepositoryFactoryForEntity <TEntity>();

            if (repoCreationMethod == null)
            {
                throw new NullReferenceException("No factory found for entity: " + typeof(TEntity).Name);
            }

            repoObject = repoCreationMethod(_dataContext);
            _repositoryCache[typeof(IBaseRepositoryAsync <TEntity>)] = repoObject;
            return((IBaseRepositoryAsync <TEntity>)repoObject);
        }