unit of work done

This commit is contained in:
Ruidy Nemausat 2020-02-17 20:57:06 +01:00
parent 172252132b
commit 4e4cc5567b
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;
namespace TicketManager.Data
{
public interface IUnitOfWork : IDisposable
{
IProjectRepository Projects { get; }
Task<int> Complete();
}
}

27
Data/UnitOfWork.cs Normal file
View file

@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
namespace TicketManager.Data
{
public class UnitOfWork : IUnitOfWork
{
private readonly AppDbContext _context;
public UnitOfWork(AppDbContext context)
{
_context = context;
Projects = new ProjectRepository(_context);
}
public IProjectRepository Projects { get; private set; }
public async Task<int> Complete()
{
return await _context.SaveChangesAsync();
}
public void Dispose()
{
_context.DisposeAsync();
}
}
}