Commit 3de96791 authored by hasan khaddour's avatar hasan khaddour

implement unit of work

parent ea519b6a
using System;
using ApplicationCore.Entities;
using ApplicationCore.Interfaces;
using Infrastructure.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -6,7 +10,33 @@ using System.Threading.Tasks;
namespace Infrastructure.UnitOfWork
{
class UnitOfWork
public class UnitOfWork<T> :IUnitOfWork<T> where T : EntityBase
{
private readonly DbContext _context;
private IGenericRepository<T> _entity;
public UnitOfWork(DbContext context)
{
_context = context;
_entity = new GenericRepository<T>(context);
}
public IGenericRepository<T> Entity
{
get
{
return _entity ?? (_entity = new GenericRepository<T>(_context));
}
}
void IUnitOfWork<T>.Save()
{
_context.SaveChanges();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment