Skip to content

Instantly share code, notes, and snippets.

@benfoster
Last active December 25, 2015 02:09
Show Gist options
  • Select an option

  • Save benfoster/6900744 to your computer and use it in GitHub Desktop.

Select an option

Save benfoster/6900744 to your computer and use it in GitHub Desktop.
A better "repository" pattern.
public interface IEntityStore
{
TEntity Get(Guid id) where TEntity : Entity
IQueryable<TEntity> Query() where TEntity : Entity
void Store<TEntity>(TEntity entity) where TEntity : Entity
void Delete<TEntity>(Guid id) where TEntity : Entity
}
@mcintyre321

Copy link
Copy Markdown

We're on the same page. I don;t know if you should feel guilty about queryable+predicates though - as long as you have a set of functional tests, you can refactor towards this approach with impunity if you feel the code is getting too messy.

I think its ok to create a ball of mud if you know you can polish it up later - one reason it's important to promote the approach here over the typical Repository.

(My preference for named delegates over the IUserQueries class is to avoid creating a class that ends up getting referenced all over the place, creating connections between namespaces. With standalone delegates you can keep them with the caller).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment