Yes, your approach is right (normal) with one Unit Of Work class/instance contains all repositories (of POCO classes).
The UoW brings 2 important things/advantages for me;
The obvious one is the ACID (Atomic, Consistency, Isolation, Durability) transactions, as only one dbcontext tracks and updates all db changes.
Unit of Work reduce a lot of dependency Injection.
Here is a complete example of using UoW with repositories;
public interface IUnitOfWork
{
IRepository<Customer> Customers { get; }
IRepository<Order> Orders { get; }
// the same for all others 8 POCO class
Task<int> SaveAsync();
}
=============================================================
public class UnitOfWork : IUnitOfWork
{
public IRepository<Customer> Customers { get; private set; }
public IRepository<Order> Orders { get; private set; }
// the same for all others 8 POCO class
private readonly MyDBContext _Context;
public UnitOfWork(MyDBContext context)
{
_dbContext = context;
Customers = new Repository<Customer>(_dbContext);
Orders = new Repository<Order>(_dbContext);
// the same for all others 8 POCO class
}
public async Task<int> SaveAsync()
{
return await _dbContext.SaveChangesAsync();
}
}
AS you can see in the above implementation that one dbContext has been used to generate all repositories. This will bring the ACID functionality.
And in your Services/Controller (or anywhere you want to use your repositories), you just need to inject only 1 UoW and can access all your repositories as:
_uow.Customers.Add(new Customer());
_uow.Ordres.Update(order);
_uow.SaveAsync();