Ninject Scope issue with Tasks/Threads

前端 未结 2 1671
失恋的感觉
失恋的感觉 2020-12-20 16:46

I have an MVC3 project that uses Ninject, Entity Framework and the Unit of Work pattern with a Service layer.

My AsyncService class has a function that starts a back

2条回答
  •  我在风中等你
    2020-12-20 17:36

    InRequestScope'd objects are Disposed at the end of a request so it can't be used in this case. InThreadScope also doesn't fit as that would reuse the UoW for several tasks.

    What you can do though is declare your AsyncService as the Scoping Object for all the objects within using the NamedScope extension.

    See http://www.planetgeek.ch/2010/12/08/how-to-use-the-additional-ninject-scopes-of-namedscope/

提交回复
热议问题