Why is my Castle Windsor controller factory's GetControllerInstance() being called with a null value?

后端 未结 4 808
遥遥无期
遥遥无期 2021-02-04 10:30

I am using Castle Windsor to manage controller instances (among other things). My controller factory looks like this:

public class WindsorControllerFactory : Def         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 11:25

    It turns out that the second request was the MVC framework trying to find a script I included in the Site.Master. The path did not exist, so I guess it tried to resolve a controller (that matched /Scripts/sitescripts.js). I changed the method to this:

    protected override IController GetControllerInstance(Type controllerType)
    {
        if (controllerType != null)
        {
           return (IController)_container.Resolve(controllerType);
        }
        else
        {
           return base.GetControllerInstance(controllerType);
        }
    }
    

    And an exception with an understandable message was thrown.

提交回复
热议问题