例如我有这个类:
public class UnitOfWork : IUnitOfWork
{
private readonly ApplicationDbContext _context;
public IProductRepository Products { get; private set; }
public ICategoryRepository Categories { get; private set; }
public IPhotoRepository Photos { get; private set; }
public UnitOfWork(ApplicationDbContext context, IProductRepository productRepository,
ICategoryRepository categoryRepository, IPhotoRepository photoRepository)
{
_context = context;
Products = productRepository;
Categories = categoryRepository;
Photos = photoRepository;
}
public int Complete()
{
return _context.SaveChanges();
}
public Task<int> CompleteAsync()
{
return _context.SaveChangesAsync();
}
public void Dispose()
{
_context.Dispose();
}
public async …Run Code Online (Sandbox Code Playgroud) c# dependency-injection idisposable unit-of-work asp.net-core