Below is my UOW class for single context with single DB.
But requirement changes Additional tables are stored in Seperate DB.
So we thought create seperate DB context i.e CPContext,CpContext2
public class UnitOfWork : IUnitOfWork, IDisposable
{
private readonly CPSContext _context;
//private readonly CPSContext _context2;
private bool _disposed;
#region Constructor
public UnitOfWork(CPSContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
// _context2= context ?? throw new ArgumentNullException(nameof(context));
#region Repositories
Banks = new BankRepository(_context);
Branches = new BranchRepository(_context);
// Ct2Repr = new Context2Repository(_context2);
#endregion
}
#endregion
#region Repositories
public IBankRepository Banks { get; private set; } = null!;
public IBranchRepository Branches { get; private set; } = null!;
//public IContext2Repository Ct2Repr { get; private set; } = null!;
#endregion
public async Task<int> CompleteAsync()
{
return await _context.SaveChangesAsync();
}
public int Complete()
{
return _context.SaveChanges();
}
#region Dispose
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_context.Dispose();
}
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
Should i create CompleteAsync for Context2?
public async Task<int> CompleteAsync()
{
return await _context.SaveChangesAsync();
}
How can i achieve this with minimal changes?