gpt4 book ai didi

c# - 为多个域实现 IRepository

转载 作者:行者123 更新时间:2023-11-30 20:53:25 25 4
gpt4 key购买 nike

我已经为多个域实现了 IRepository 接口(interface),但我不知道如何调用具体方法。

代码如下:

public interface IRepository<T> where T : class
{
IEnumerable<T> GetAll();
void Add(T entity);
void Update(T entity);
}


public interface IProjectRepository : IRepository<ProjectType>, IRepository<Project>, IRepository<ProjectDetail>
{
}

public class ProjectRepository : IProjectRepository
{
// implemenation

}

现在,当我创建 ProjectRepository 类的对象时,它会显示接口(interface)的所有方法,但只需要 projecttype 参数。

我不知道,这是正确的实现方式吗?或者还有其他方法可以实现类似的东西吗?

最佳答案

通用存储库 IRepository<T> IMO 不是一个好的解决方案,请查看 http://www.sapiensworks.com/blog/post/2012/03/05/The-Generic-Repository-Is-An-Anti-Pattern.aspx

我认为最好在没有通用参数和通用方法的情况下单独指定每个存储库(您确定在所有存储库中始终需要 AddUpdateGetAll 吗?)

关于c# - 为多个域实现 IRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com