Where should SaveChanges() reside- in Unit of Work or in Generic repository?

17 hours ago 4
ARTICLE AD BOX

I am implementing a standard Repository pattern(Controller -> Service -> Repository) in an ASP.NET Web API project using Entity Framework Core. I have a GenericRepository<T> for CRUD operations and an IUnitOfWork to manage transactions.

My IUnitOfWork currently handles BeginTransaction(), Commit(), Rollback(), Dispose() and Save() methods.

I am facing a dilemma regarding the placement of the Save() (or SaveChangesAsync) method:
1. Should it say in the IUnitofWork? If so, then if I have a service class that works with single repository, I would have to inject the UoW just for the Save() method. It seems like an overhead.
2. Should it be in the GenericRepository<T>? If so, should it be in individual CRUD methods or as a separate method which calls DbContext.SaveChanges simply?

I understand that EF Core already implements UnitOfWork for me, but I've been recommended to do it like this. I'm confused on this part.

Thanks in advance.

Read Entire Article