asp.net mvc - Dependency Injection without Repository Pattern using with Entity Framework -
asp.net mvc - Dependency Injection without Repository Pattern using with Entity Framework -
so far i've been implementing in projects repository pattern , dependency injection. utilize entity framework orm , have service layer manages repositories.
i kind of sense doing not essential problems @ hand. not alter database or orm. little projects have no need implement tests.
but thought of not sending requests database each time fetch data, if it's in memory there.
my question is: if utilize entiry framework illustration in asp.net mvc application, , not utilize repository pattern, still using di on ef's dbcontext, can benefit of performance preventing roundtrips database server reads?
by implementing di on dbcontext mean ninject example:
kernel.bind<mydbcontext>().toself().inrequestscope();
thanks
adding repository pattern on top of ef dbcontext
not help in performance optimization.
the dbcontext
unit of work keeps track of loaded/changed/added entities. idbset<t>
repository. dbcontext
has list of repositories. dbcontext
responsible doing performance optimisations not loading same entity twice rather homecoming same instance when load twice id. of course, apply must reuse same dbcontext
instance. if create 2 dbcontext
instances, both load same entity once.
so using
kernel.bind<mydbcontext>().toself().inrequestscope();
and not putting own "repository pattern" on top of mydbcontext
fine.
asp.net-mvc entity-framework dependency-injection ninject ninject.web.mvc
Comments
Post a Comment