Below is NinjectHttpApplication configuration..
public class MvcApplication : NinjectHttpApplication
{
public MvcApplication()
{
Error += NinjectWebsiteApplication_Error;
}
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load<ApplicationConfig>();
return kernel;
}
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
ILogger _iLogger = **//How to get instance of Applogger here from Ninject kernel..**
}
Below is the ApplicationConfig class...
public class ApplicationConfig : NHibernateNinjectModule
{
public ApplicationConfig()
{
//other settings such as ddl script generation is present here
}
public override void Load()
{
base.Load();
Bind<ILogger>().To<AppLogger>().InSingletonScope();
}
}
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
var kernel = CreateKernel();
ILogger _iLogger = kernel.Get<ILogger>();
}
Ok, as it seems NinjectHttpApplication
stores generated kernel object in
public IKernel Kernel
{
get { return _kernel; }
}
So you could rewrite above as
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
ILogger _iLogger = Kernel.Get<ILogger>();
}
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