Last active
December 15, 2015 22:19
-
-
Save yemrekeskin/5331974 to your computer and use it in GitHub Desktop.
Using Unit Of Work Design Pattern
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 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