Skip to content

Instantly share code, notes, and snippets.

@Deathspike
Created January 20, 2016 09:09
Show Gist options
  • Save Deathspike/52bacda59784cc0668c2 to your computer and use it in GitHub Desktop.
Save Deathspike/52bacda59784cc0668c2 to your computer and use it in GitHub Desktop.
EF6+ UoW Decorator
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
}
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