无法从IGenericReporsitoty 转换为IGenericReporsitoty

问题描述 投票:0回答:1

我的控制器出现错误。无法将存储库注入基本构造函数中

public class MyController : ControllerCRUDBase<Entity, TournamentDto>
{
    public MyController (IGenericRepository<Entity> repository, IMapper mapper) 
        : base(repository, mapper)
    {
    }
}

我的ControllerCRUDBase在哪里:

public abstract class ControllerCRUDBase<E, D> : ControllerBase
        where E : EntityBase
        where D : DtoBase
    {
        protected readonly IGenericRepository<EntityBase> _repository;
        protected readonly IMapper _mapper;

        public ControllerCRUDBase(IGenericRepository<EntityBase> repository,
                                  IMapper mapper)
        {
            _repository = repository;
            _mapper = mapper;
        }

我的IGenericRepository是:

public interface IGenericRepository<TEntity> where TEntity : EntityBase
    {
    }

并且Entity类是:

public class Entity: EntityBase
{
}

错误是这样:

cannot convert from 'IGenericRepository<Entity>' to 'IGenericRepository<EntityBase>'

而且我不明白为什么。

c# .net-core typeconverter
1个回答
0
投票
public abstract class ControllerCRUDBase<E, D> : ControllerBase where E : EntityBase where D : DtoBase { protected readonly IGenericRepository<E> _repository; protected readonly IMapper _mapper; public ControllerCRUDBase(IGenericRepository<E> repository, IMapper mapper) { _repository = repository; _mapper = mapper; } }
© www.soinside.com 2019 - 2024. All rights reserved.