Created
February 24, 2016 03:13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Northwind.Repository.Api; | |
using System.Data; | |
namespace Northwind.Repository.Service | |
{ | |
public class UnitOfWork : IUnitOfWork | |
{ | |
private IDapperContext _context; | |
private IDbTransaction _transaction; | |
private ICategoryRepository _categoryRepository; | |
private IProductRepository _productRepository; | |
public UnitOfWork(IDapperContext context) | |
{ | |
this._context = context; | |
} | |
public ICategoryRepository CategoryRepository | |
{ | |
get { return _categoryRepository ?? (_categoryRepository = new CategoryRepository(_transaction, _context)); } | |
} | |
public IProductRepository ProductRepository | |
{ | |
get { return _productRepository ?? (_productRepository = new ProductRepository(_transaction, _context)); } | |
} | |
public void BeginTransaction() | |
{ | |
if (_transaction != null) | |
throw new NullReferenceException("Not finished previous transaction"); | |
_transaction = _context.db.BeginTransaction(); | |
} | |
public void Commit() | |
{ | |
if (_transaction == null) | |
throw new NullReferenceException("Tryed commit not opened transaction"); | |
_transaction.Commit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment