Created
January 20, 2016 09:09
-
-
Save Deathspike/52bacda59784cc0668c2 to your computer and use it in GitHub Desktop.
EF6+ UoW Decorator
This file contains hidden or 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
public abstract class ContextDecorator : IContext | |
{ | |
private readonly IContext _context; | |
#region Constructor | |
protected ContextDecorator(IContext context) | |
{ | |
_context = context; | |
} | |
#endregion | |
#region Implementation of IContext | |
public virtual int SaveChanges() | |
{ | |
return _context.SaveChanges(); | |
} | |
public virtual IContextMapper<Account> Accounts | |
{ | |
get { return _context.Accounts; } | |
} | |
#endregion | |
#region Implementation of IDisposable | |
public void Dispose() | |
{ | |
_context.Dispose(); | |
} | |
#endregion | |
} |
This file contains hidden or 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
public class UserDecorator : ContextDecorator | |
{ | |
private readonly long _accountId; | |
#region Constructor | |
public UserDecorator(IContext context, long accountId) : base(context) | |
{ | |
_accountId = accountId; | |
} | |
#endregion | |
#region Overrides of ContextDecorator | |
public override IContextMapper<Account> Accounts | |
{ | |
get { return base.Accounts.Where(x => x.Id == _accountId); } | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment