I am using AJAX-enable web services in my ASP.NET MVC3 application and I want to inject some classes in to them. So I installed NInject.Wcf, set factory to Ninject.Extensions.Wcf.NinjectServiceHostFactory
and next step is derive application class(MVCApplication
in Global.asax) from NinjectWcfApplication
, but when I have done this, IIS stopped to run my application, it tries to use StaticFile module rather than route request to controller.
How to fix this or how to implement NInject with WCF in other way?
I finally figured out it, the reason why routes has not been setup correctly is because of default Global.asax template for ASP.NET MVC application, by default it defines
void Application_Start() { ... }
and since HttpApplication don't have this method defined IIS call this method on start up. So when deriving from NinjectWcfApplication
which have defined Application_Start method, we need to change default method to:
protected override void Application_Start(object sender, EventArgs e)
{
.....
base.Application_Start(sender, e);
}
if we don't do this IIS will call NinjectWcfApplication.Application_Start
instead of our Application_Start
method.