entity framework 4.1 - Generic Repository With EF 4.1 what is the point -


as dig deeper in dbcontext, dbset , associated interfaces, wondering why need implement separate "generic" repository around these implementations?

it looks dbcontext , idbset need , include "unit of work" inside dbcontext.

am missing here or seem people enjoy adding layer of dependency no reason.

you right. dbcontext implementation of unit of work pattern , idbset implementation of repository pattern.

repositories popular , overused. use them because there dozens of articles creating repository entity framework nobody describes challenges related decision.

main reasons using repository usually:

  • hide ef upper layer
  • make code better testable

the first reason kind of architectonic purity , great idea if make upper layers independent on ef can later on switch other persistence framework. how many times did see such thing in real world? reason makes working ef harder because repository must expose lot of additional features wrapping ef allows default.

in same time wrapping ef code can keep code better organized , following separation of concern rule. me can real advantage of repository , unit of work have understand following rule ef maybe make code better maintainable , better readable in initial effort create application higher , smaller applications can unnecessary complexity.

the second reason partially correct. big disadvantage of ef rigid architecture can hardly mocked if want unit test upper layer must wrap ef somehow allow mocking implementation. has many other consequences described here.

i follow ayende's blog. if ever used nhibernate know articles. guy wrote several articles against using repository nhibernate nhibernate better mockable.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -