I am new in Ninject and I need some help to move on.
I have a solution that consists of web.form (presentation) and various other class libraries projects.
In web.form application inside NinjectWebCommon cs file I have the following
kernel.Bind<HttpContext>()
.ToMethod(ctx => HttpContext.Current).InThreadScope();
kernel.Bind<HttpContextBase>()
.ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
kernel.Bind<MPIBE.DESTINATION.CORE.SiteContext>()
.ToMethod(ctx => new MPIBE.DESTINATION.CORE.SiteContext(
new HttpContextWrapper(HttpContext.Current)
));
I am trying to get an instance of a class (following the constructor)
public SessionUtilities(SiteContext siteContext)
{
_siteContext = siteContext;
}
and I noticed that i can get the instance only form web.forms application and I can't get from other projects (class libraries). Does this make any sense?
I am trying to get the instance via property injection
[Inject]
public SessionUtilities _sessionUtilities { get; set; }
I suspect the class that contains your _sessionUtilities
property is being created with new
instead of via Ninject.
Ninject will only inject your _sessionUtilities
property if the containing instance is also created by Ninject, either because it is created with kernel.Get()
or because it is itself being injected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With