title: Advice With Repository/Service Layer Design Pattern
body: <p>Trying to make a really simple repository and service layer pattern here. (.NET 4, C#, LINQ, although this question is partially language-agnostic). Note: this is just R&amp;D.</p>
  
  <p>My goal is to minimize the amount of method definitions in my service layer.</p>
  
  <p>Here's my Repository Contract:</p>
  
  <pre><code>interface IFooRepository
  {
     IEnumerable&lt;Foo&gt; Find();
     void Insert(Foo foo);
     void Update(Foo foo);
     void Delete(Foo foo);
  }
  </code></pre>
  
  <p>Nothing new there.</p>
  
  <p>Now, here's what im (trying) to have in my Service Contract:</p>
  
  <pre><code>interface IFooDataService
  {
     public IEnumerable&lt;Foo&gt; Find(FooSearchArgs searchArgs);
  }
  </code></pre>
  
  <p>Essentially, any particular "Foo" has many properties (id, name, etc), which i would like to be able to search upon.</p>
  
  <p>So, i dont want to have 1x Find method for each different property, i just want one - that way when i create extra properties i dont have to modify the contracts.</p>
  
  <p>The "FooSearchArgs" is just a simple POCO with all the different "Foo" properties it.</p>
  
  <p>So, that's what im trying to do, here's my questions:</p>
  
  <ul>
  <li>Is this poor design? If so, what are the alternatives?</li>
  <li>How can i implement this filtering in the service layer? Would i have to check what properties of "FooSearchArgs" are set, then keep filtering down? (if this, then query.where, if this, query.where, etc) Anyone have an idea of a clever LINQ IEnumerable extension method to do this? (ie <code>repository.WhereMeetsSearchCriteria(fooSearchArgs)</code>)</li>
  </ul>
  
  <p>Appreciate the help.</p>