开发者

Ninject InRequestScope missing

开发者 https://www.devze.com 2023-03-25 19:59 出处:网络
Have a couple of questions regarding the latest version (2.2.1.4) of ninject. Was trying to Bind a Linq2sql DataContext to a concrete implementation InRequestScope (in a class library project)

Have a couple of questions regarding the latest version (2.2.1.4) of ninject.

Was trying to Bind a Linq2sql DataContext to a concrete implementation InRequestScope (in a class library project)

Bind<DataContext>().To<MoneywatchDataContext>()

but could not find InRequestScope met开发者_如何学JAVAhod

Ninject InRequestScope missing

ended up doing this,

Bind<DataContext>().To<MoneywatchDataContext>().InScope(ctx => HttpContext.Current)

Just wanted to find out if:

  1. If this will behave exactly like the InRequestScope Method.
  2. That it will gurantee that when my HTTContext.Current is GC'ed the underlying DataCotext will be disposed as well.


InRequestScope is available as extension method in Ninject.Web.Common. So if installed earlier through Nuget (Ninject package) now we might need to install additional nuget package Ninject.Web.Common


using Ninject.Web.Common;    // that's most likely all you need


Most likely you reference a no web version of Ninject. Replace it with the normal version and you will have the InRequestScope extension method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号