Why does the HomeController get the link, and how do I maintain it (if I should)?

This is a kind of situation with Helleresque (Catch-22); or perhaps more adequately "inappropriate if I do this, and would not be installed if I do not"

With this castle Windsor Controller Factory:

public class WindsorControllerFactory : DefaultControllerFactory
{
    private readonly IKernel _kernel;

    public WindsorControllerFactory(IKernel kernel)
    {
        _kernel = kernel; 
        //According to http://docs.castleproject.org/Windsor.Typed-Factory-Facility.ashx, might need this:
        //_kernel.AddFacility<TypedFactoryFacility>(); // This breaks ("Typed factory facility already registered"), so commenting it out; see http://stackoverflow.com/questions/20914635/how-do-i-connect-the-various-pieces-of-my-web-api-castle-windsor-di-code
        //but that requires uncommenting the "TypedFactory" using above.
    }

    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        if (controllerType == null)
        {
            throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
        }
        return (IController)_kernel.Resolve(controllerType);
    }

    public override void ReleaseController(IController controller)
    {
        _kernel.ReleaseComponent(controller);
    }

}

If this line is live:

_kernel.AddFacility<TypedFactoryFacility>();

... I get this exception at runtime: "TypedFactoryFacility" is already registered in the container

... if I comment on this line, I get this exception at runtime:

"No component to support HandheldServer.Controllers.HomeController service was found."

... in this line:

return (IController)_kernel.Resolve(controllerType);

Why does the HomeController get the link and how do I maintain it (if I should)?

HomeController is the default class, which looks like this:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.Title = "Home Page";

        return View();
    }
}

HomeController? ...???

UPDATE

HomeController :

public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.Title = "Home Page";

        return View();
    }
}

... :

public class HomeController : ApiController
{
}

, :

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
    if (controllerType == null) // <-- now controllerType is null
    {
        throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
    }
    return (IController)_kernel.Resolve(controllerType); 
}

... is: "System.Web.HttpException HResult = -2147467259 = '/' . = HandheldServer ErrorCode = -2147467259 WebEventCode = 0 :       HandheldServer.DIPlumbing.WindsorControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) c:\HandheldServer\HandheldServer\DIPlumbing\WindsorControllerFactory.cs: 36       System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)       System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController & controller, IControllerFactory & factory)       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback, )       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback, )       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest( HttpContext, AsyncCallback cb, extraData)       System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()"

0
1

, .

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
+1

All Articles