ASP.NET MVC inject per request

后端 未结 3 991
抹茶落季
抹茶落季 2020-12-09 14:25

I need to inject EF context per request. Is there any way to implement it?

3条回答
  •  粉色の甜心
    2020-12-09 14:53

    What do you mean by injecting? Do you mean to apply dependency inversion principle on it? If yes then do you ever envisage yourself swapping out your EF context with some other context which adheres to same contract?

    To me you should encapsulate EF context somewhere in framework, so that every request gets EF DataContext. Apply DI on your repository. Later on your repositories might have different kind of contexts and you can switch repositories with each other.

提交回复
热议问题