由于 "no implicit reference conversion",无法注入 IRepository<TEntity>

Unable to inject IRepository<TEntity> due to "no implicit reference conversion"

开始尝试熟悉 .NET Core 的 ASP.NET 样板模板。

一切都进行得很顺利,直到我需要将带有通用 EntityIRepository 注入到 class 构造函数中。

DepartmentManager class 中,当我尝试创建一个私有只读字段以注入到构造函数中时,我收到以下 IntelliSense 错误:

There is no implicit reference conversion from Department to Abp.Domain.Entities.IEntity The Type Department cannot be used as type parameter TEntity in the generic type or method 'IRepository, primary key'

我尝试研究是否可以在网上找到类似问题的一些解决方案,但无济于事。

下面是一个简单的代码来说明这个挑战。

// Class 
public class Department
{
    public long Id { get; set; }

    public string DepartmentName { get; set; }
}

// IDepartment Manager
public interface IDepartmentManager
{
    Task<Department> CreateDepartment(Department entity);
    Task Update(Department entity);
    Task Delete(long id);
    Task<IEnumerable<Department>> GetAll();
}

// Department Manager    
private readonly IRepository<Department, long> _departmentRepo;
public DepartmentManager(IRepository<Department, long> departmentRepo)
{
    _departmentRepo = departmentRepo
}

对于我做错的地方,非常感谢任何帮助。

使 Department 实现 Entity<long>IEntity<long> 以使用其存储库。

public class Department : Entity<long>
{
    public string DepartmentName { get; set; }
}

参考资料