Search code examples
asp.net-mvc-4controller-factory

IControllerFactory.CreateController gets called for every controller in every request


I'm having an issue that, while not critical, still called my attention. I happen to have an MVC4 web application where I've replaced the default controller factory for one implemented by myself, within this factory I use unity to inject the constructor parameters for the controller.

What I don't understand is why, for each and every request I make, the CreateController method gets called for every controller in the application and not just the one in the url and the ones called by partial views.

Is that behaviour normal? Is it necessary or is there a way to prevent it? I see no reason for this and my research hasn't lead me to any good answer.

Thanks!


Solution

  • Ha! It turns out that when you use mvc sitemap solution it builds every controller for every request, by removing this line, that weird behaviour didn't happen anymore

    @Html.MvcSiteMap().SiteMapPath()
    

    Thanks anyway for the ones who read this and I hope someone finds this useful!