Why are my controllers being instantiated when they're not being called?

前端 未结 2 1831
我寻月下人不归
我寻月下人不归 2021-01-17 00:38

Here are the symptoms I am experiencing:

I have a brand new empty controller in an area:

public class JamController : Controller
{
    public JamCo         


        
2条回答
  •  死守一世寂寞
    2021-01-17 01:26

    Turns out that the SetControllerFactory method below is causing the issue:

    // Tell MVC3 to use MEF as its dependency resolver.
    var dependencyResolver = new CompositionDependencyResolver(catalog);
    DependencyResolver.SetResolver(dependencyResolver);
    
    // Tell MVC3 to resolve dependencies in controllers
    ControllerBuilder.Current.SetControllerFactory(
        new CompositionControllerFactory(
            new CompositionControllerActivator(dependencyResolver)));
    

    Commenting out the "Tell MVC3 to resolve dependencies in controllers" section fixes my issue, and no controllers except those I ask for get instantiated. Luckily, that's only needed if you're not using the standard Asp.Net controller resolution (and we are).

提交回复
热议问题