Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Last active December 15, 2015 22:19
Show Gist options
  • Save yemrekeskin/5331974 to your computer and use it in GitHub Desktop.
Save yemrekeskin/5331974 to your computer and use it in GitHub Desktop.
Using Unit Of Work Design Pattern
// using Unit Of Work Pattern
public interface IUnitOfWork
{
void Commit();
}
/// <summary>
/// Universal Repository de diyebiliriz
/// </summary>
public class UnitOfWork
:IUnitOfWork
{
private IContextFactory _contextFactory;
private SampleContext _context;
public SampleContext Context
{
get
{
return this._context ?? (_context = _contextFactory.GetContext());
}
}
public UnitOfWork(IContextFactory contextFactory)
{
this._contextFactory = contextFactory;
}
public UnitOfWork()
{
this._contextFactory = new ContextFactory();
}
public void Commit()
{
this.Context.Commit();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
Context.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#region Repositories
private CategoryRepository _categoryRepository;
protected CategoryRepository CategoryRepository
{
get { return this._categoryRepository ?? (_categoryRepository = new CategoryRepository(_contextFactory)); }
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment