Ninject InRequestScope missing
Asked Answered
P

3

34

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 method

enter image description here

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.
Poll answered 2/8, 2011 at 12:13 Comment(0)
R
23

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

Rohn answered 2/8, 2011 at 13:4 Comment(0)
A
50

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

Athlete answered 27/3, 2012 at 12:18 Comment(2)
Remeber that you need to install this package on the project that your module class is being configured. I had a problem in which I have installed it in the MVC project but the module where I put Bind<>().To<>().InRequestScope(); was in the Infrastucure project. I took me a while to realize that.Exclamation
That was it! Thanks.Chagres
C
35
using Ninject.Web.Common;    // that's most likely all you need
Compilation answered 14/12, 2012 at 8:58 Comment(2)
This is the actual answer that helped me.Equable
(this imports the namespace containing the extension method)Compilation
R
23

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

Rohn answered 2/8, 2011 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.