Appropriate Repository LifeCycle Scope w/ Ninject in MVC

后端 未结 2 1474
天涯浪人
天涯浪人 2021-02-10 01:51

What is the appropriate LifeCycle Scope for a repository and the EF context when using Entity Framework 4 with Ninject in an MVC 3 application?

I\'ve been using the defa

2条回答
  •  不要未来只要你来
    2021-02-10 02:27

    This depends on a couple of factors.

    1. Do you care about transactions at all? It not that transient scope is ok for you.

    2. Do you care about transactions but think one transaction per web request is ok for you? Then use web scoped.

    3. Are you ok with objects being "cached" in EF's context and don't want a full database refresh if you request the same object twice? Web scope has this side effect.

提交回复
热议问题