// ====================================== // Author: Ebenezer Monney // Email: info@ebenmonney.com // Copyright (c) 2017 www.ebenmonney.com // // ==> Gun4Hire: contact@ebenmonney.com // ====================================== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DAL.Repositories; using DAL.Repositories.Interfaces; namespace DAL { public class UnitOfWork : IUnitOfWork { readonly ApplicationDbContext _context; ICustomerRepository _customers; IProductRepository _products; IOrdersRepository _orders; public UnitOfWork(ApplicationDbContext context) { _context = context; } public ICustomerRepository Customers { get { if (_customers == null) _customers = new CustomerRepository(_context); return _customers; } } public IProductRepository Products { get { if (_products == null) _products = new ProductRepository(_context); return _products; } } public IOrdersRepository Orders { get { if (_orders == null) _orders = new OrdersRepository(_context); return _orders; } } public int SaveChanges() { return _context.SaveChanges(); } } }