Home  /  Questions  /  Question



55   94.7
Nov 21, 2010


Generic Repository-based interface

Hi there, I have a question:
Why is the generic Repository-based interface in the MVC Application project and why not in Data Layer project?

Thanks



1,364   100.0
Jan 06, 2011
I am not sure which context you are referring to, but as a general practice the "Generic Repository" interface should not be in the MVC application project.  It should be in a separate class library for ease of reuse and from maintenance point of view.

588   99.9
Jan 07, 2011
Yassin,

If you are talking about the Patterns In Action 4.0 MVC application, then it's there to provide a base implementation to the UI repositories.  The DoFactory guys can correct me if I'm wrong about this, but what this does in this particular pattern is provide a layer of abstraction in the UI for, what I see as three immediate reasons:

  1. WCF abstraction - the repository base abstracts away the actual implementation of the WCF proxy, so this way you aren't accessing it directly in the controllers.  The next reason explains why.
  2. Testability - by referencing repository interfaces instead of the WCF proxy client, you can now test your controllers, which in MVC is huge and necessary.
  3. DRY - Don't repeat yourself.  This class also provide access to a commonly used Correlate method that validates that your request and response matches.  You can also place other reusable methods here that help you process your code.
By designing the framework this way, they've given you access to WCF services and kept the controllers testable.  This is a "Win win".

I hope that answers your question.

King Wilder