I have a pretty standard Repository pattern going, where repositories are injected into my MVC controller at construction. Repositories are initialized once per AppDomain and are shared by other controllers. Repositories access the database using NHibernate ISessions and ICriteria, but access is exposed using ListXYZ methods instead of accepting ICriteria directly.
I now need a neat way to restrict the results returned in certian cases, one such may for example be listing all products in a given market, known only when an action is called.
I don't want to pass this restriction in at each call to a ListXYZ method since it would lead to a lot of overloaded methods. Ideally I would like to be able to access the repository like before but with the restrictions applied. Something like:
var rep = new ProductRepository().ApplyRestriction(new MarketRestriction("xy"));
var list = rep.ListInCategory("shirts");
Any suggestions How I should do this? Or am I making it too complicated for myself?