EF - and repository pattern - multiple contexts

前端 未结 3 1167
野趣味
野趣味 2020-12-17 07:06

I\'ve faced some troubles with context in EF in ASP.MVC2.

I thought that best way to improve some operation on DataBase i\'ve created Repository. My repo class adds,

3条回答
  •  不知归路
    2020-12-17 07:36

    A context is a unit of work, so you want one per web request.

    Therefore, you should use constructor injection (i.e., a constructor argument) to supply a single context for all repositories, and dispose it at the end of the request.

    Most DI frameworks will do this automatically.

提交回复
热议问题