Entity framework、IRepository 和 UnitOfWork。你如何实施 DAL?
Entity framework, IRepository and UnitOfWork. How do you implement DAL?
Canonical implementation of Repository 使用 EF 看起来像:
public interface IStudentRepository : IDisposable
{
IEnumerable<Student> GetStudents();
Student GetStudentByID(int studentId);
void InsertStudent(Student student);
void DeleteStudent(int studentID);
void UpdateStudent(Student student);
void Save();
}
在这里我看到了 IRepository、UnitOWork 的组合。
但是 Fowler 说存储库是 collection-like interface for accessing domain objects。据此,Update、Delete 和 Insert 方法应移至另一个 class。以及保存应该移动到 class 实现 IUnitOfWork。
在我当前的项目中,我们按照官方文档所述实现了 IRepository。它会在未来造成问题吗?一种解决方案是实施 CQRS,也许使用事件溯源,但这需要时间和资源。那么,您是如何在您的项目中实现DAL的呢?
你那里的东西没有问题。
我唯一做的额外工作是为我的存储库创建一个单例工厂,它是 DataService class 的一部分。 DataService class 将交付存储库实例
Canonical implementation of Repository 使用 EF 看起来像:
public interface IStudentRepository : IDisposable
{
IEnumerable<Student> GetStudents();
Student GetStudentByID(int studentId);
void InsertStudent(Student student);
void DeleteStudent(int studentID);
void UpdateStudent(Student student);
void Save();
}
在这里我看到了 IRepository、UnitOWork 的组合。
但是 Fowler 说存储库是 collection-like interface for accessing domain objects。据此,Update、Delete 和 Insert 方法应移至另一个 class。以及保存应该移动到 class 实现 IUnitOfWork。
在我当前的项目中,我们按照官方文档所述实现了 IRepository。它会在未来造成问题吗?一种解决方案是实施 CQRS,也许使用事件溯源,但这需要时间和资源。那么,您是如何在您的项目中实现DAL的呢?
你那里的东西没有问题。
我唯一做的额外工作是为我的存储库创建一个单例工厂,它是 DataService class 的一部分。 DataService class 将交付存储库实例