I have a new MVC 2 project using ninject 2 for IOC. I have the following global.asax which sets up both NHibernate and Ninject. The code runs fine, ninject pulls out the controllers from the assembly (it does convert them to lowe case strings when it does this - inside the Ninject source).
All my controller URL's are now case sensitive so, /Home won't resolve but /home will.
When I use an uppercase first letter (the defualt in MVC) I get the error "The IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for the name 'Home'."
Surly this isn't normal? Any Ideas?
public class MvcApplication : NinjectHttpApplication { public static ISessionFactory SessionFactory = CreateSessionFactory(); public MvcApplication() { this.BeginRequest += new EventHandler(MvcApplication_BeginRequest); this.EndRequest += new EventHandler(MvcApplication_EndRequest); }
void MvcApplication_BeginRequest(object sender, EventArgs e)
{
CurrentSessionContext.Bind(SessionFactory.OpenSession());
}
void MvcApplication_EndRequest(object sender, EventArgs e)
{
CurrentSessionContext.Unbind(SessionFactory).Dispose();
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
private static ISessionFactory CreateSessionFactory()
{
var cfg = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nhibernate.config"));
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @"Data Source=.\;Initial Catalog=xxxxxx;Integrated Security=true;");
//cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, System.Environment.MachineName);
NHibernateProfiler.Initialize();
return cfg.BuildSessionFactory();
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new INinjectModule[] {
new ServiceModule(),
});
}
}