NikitaKo
NikitaKo

Reputation: 310

Entity framework, IRepository and UnitOfWork. How do you implement DAL?

Canonical implementation of Repository with EF looks like:

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();
}

Here I see mix of IRepository, UnitOWork.

But Fowler says that repository is collection-like interface for accessing domain objects. According to that, Update, Delete and Insert methods should be moved to another class. As well as Save should be moved to class implementing IUnitOfWork.

In my current project we implement IRepository as official documentation says. Can it cause problems in future? One solution would be implement CQRS, maybe with event-sourcing, but it will take time and resources. So, how do you implement DAL in your projects?

Upvotes: 3

Views: 121

Answers (1)

Ross Miller
Ross Miller

Reputation: 646

Nothing wrong with what you have there.

The only thing extra I do is I create a singleton factory for my repository which is part of a DataService class. The DataService class would delivery repository instances

Upvotes: 3

Related Questions