db: refactor to only init mongo client & collections once

This commit is contained in:
Abdullah Atta
2024-06-07 15:39:12 +05:00
parent c5b41be2fd
commit 99f095babe
4 changed files with 23 additions and 57 deletions
+3 -11
View File
@@ -23,24 +23,16 @@ using Streetwriters.Data.Interfaces;
namespace Streetwriters.Data
{
public class UnitOfWork : IUnitOfWork
public class UnitOfWork(IDbContext dbContext) : IUnitOfWork
{
private readonly IDbContext dbContext;
public UnitOfWork(IDbContext _dbContext)
{
dbContext = _dbContext;
}
public async Task<bool> Commit()
{
var changeAmount = await dbContext.SaveChanges();
return changeAmount > 0;
return await dbContext.SaveChanges() > 0;
}
public void Dispose()
{
this.dbContext.Dispose();
dbContext.Dispose();
}
}
}