views:

147

answers:

1

Hello everybody,

What are the pros and cons of using static repositories in an ASP.NET MVC application?

Wouldn't it be better to have all the methods available all the time -> means that the class get's instantiated only once instead of having multiple controllers referencing to the same repository class and its methods?

Or do I get something wrong here?

All help is more than appreciated!

+3  A: 

Pros:

  • Repository is accessible everywhere

Cons:

  • Repositories don't implement a contract which leads to a strong coupling between consumers of the repository and the implementation
  • Impossible to unit test
  • Might run into threading issues

Remark: Instantiating the repository on every request shouldn't be regarded as a performance issue.

Darin Dimitrov
I think that clears things up! Thanks! :-)
Shaharyar