Entity Framework Core 1.0 DbContext not scoped to http request

后端 未结 1 2079
刺人心
刺人心 2021-02-10 23:52

I understood by watching this video with Rowan Miller https://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/06 (at minute 22) that the way of configuring Ent

1条回答
  •  情深已故
    2021-02-11 00:20

    After more testing I can confirm that the DbContext is scoped to the http request only during the lifetime of the MVC execution (maybe MVC is in charge of disposing of the DbContext), so any middleware before or after in the pipeline won't have the same instance of DbContext injected.

    I decided then to add a global filter to MVC 6 (because filters are part of MVC framework) so that I can access the same DbContext instance before and after the action's execution.

    If anybody is interested on how to create this global filter check: Entity Framework Core 1.0 unit of work with Asp.Net Core middleware or Mvc filter

    0 讨论(0)
提交回复
热议问题