Inject a dependency into a custom model binder and using InRequestScope using Ninject

前端 未结 3 1333
无人及你
无人及你 2020-12-03 22:53

I\'m using NInject with NInject.Web.Mvc.

To start with, I\'ve created a simple test project in which I want an instance of IPostRepository to be shared

3条回答
  •  长情又很酷
    2020-12-03 23:49

    The ModelBinders are reused by MVC for multiple requests. This means they have a longer lifecycle than request scope and therefore aren't allowed to depend on objects with the shorter request scope life cycle.

    Use a Factory instead to create the IPostRepository for every execution of BindModel

提交回复
热议问题