EFCore.GenericRepository icon indicating copy to clipboard operation
EFCore.GenericRepository copied to clipboard

Supporting UnitOfWork

Open mehdihadeli opened this issue 4 years ago • 5 comments

Hi, Thanks for your good implementation. I have a suggestion, In my opinion it is better we have a separated UnitOfWork pattern on top of this repository instead of doing SaveChanges inner repository because it is not responsibility of a repository, and it breaks single responsibility.

mehdihadeli avatar Dec 06 '21 18:12 mehdihadeli

@mehdihadeli I am still not sure about whether should I change this or not. But If I do this, then it will be a huge breaking change that will break existing applications.

TanvirArjel avatar Dec 16 '21 17:12 TanvirArjel

Generic Repositories are often considered an anti-pattern (in the Entity Framework world), thats beacuse the SaveChanges() is affecting all tracked entities. Maybe this problem can be resolved in such a way as to provide two types of repositories. One standard IRepositry<T> without exposed SaveChanges() placed in IUnitOfWork with the SaveChanges()/Commit() method and the other ITrackedRepository<T> which also includes the option of saving the transaction. This is not a solution to the problem, but it requires you to do something about the problem from the code level. I can post an implementation of my proposal.

Krzysztofz01 avatar Jan 25 '22 17:01 Krzysztofz01

@Krzysztofz01

This is not a solution to the problem, but it requires you to do something about the problem from the code level. I can post an implementation of my proposal.

Of course, you can!

TanvirArjel avatar Feb 15 '22 13:02 TanvirArjel

Personally, don't like the idea of UoW while using EF. It's an unnecessary level of abstraction and it will make the library heavier and complicated. Been using only the Repository pattern and transactions without any issue so far, although I understand there might be valid usages for it. I like this library because of it's simplicity.

HybridSolutions avatar Mar 16 '22 16:03 HybridSolutions

Please share your thoughts in : https://github.com/TanvirArjel/EFCore.GenericRepository/issues/25

TanvirArjel avatar Jun 10 '22 16:06 TanvirArjel