title: IoC Castle Windsor in MVC routing problem
body: <p>I've set up castle windsor in my mvc app. everything works great except it also catches routes that are of type link or image. The problem is that right before exiting from the controller and generating the view "GetControllerInstance" is executed with 'null' type. This happends anytime there a link on a page like:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="non-existing.css"/&gt;
  </code></pre>
  
  <p>Or a link to an image that does not exist. Why is this happening?</p>
  
  <p>My windows class:</p>
  
  <pre><code>    public class WindsorControllerFactory : DefaultControllerFactory
  {
      #region Constants and Fields
  
      /// &lt;summary&gt;
      /// The container.
      /// &lt;/summary&gt;
      private readonly WindsorContainer container;
  
      #endregion
  
      // The constructor:
      // 1. Sets up a new IoC container
      // 2. Registers all components specified in web.config
      // 3. Registers all controller types as components
      #region Constructors and Destructors
  
      /// &lt;summary&gt;
      /// Initializes a new instance of the &lt;see cref="WindsorControllerFactory"/&gt; class.
      /// &lt;/summary&gt;
      public WindsorControllerFactory()
      {
          // Instantiate a container, taking configuration from web.config
          this.container = InversionOfControl.Container;
  
          // Also register all the controller types as transient
          IEnumerable&lt;Type&gt; controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                                              where typeof(IController).IsAssignableFrom(t)
                                              select t;
          foreach (Type t in controllerTypes)
          {
              this.container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
          }
      }
  
      #endregion
  
      #region Methods
  
      /// &lt;summary&gt;
      /// The get controller instance.
      /// &lt;/summary&gt;
      /// &lt;param name="requestContext"&gt;
      /// The request context.
      /// &lt;/param&gt;
      /// &lt;param name="controllerType"&gt;
      /// The controller type.
      /// &lt;/param&gt;
      /// &lt;returns&gt;
      /// Resolved controller instance.
      /// &lt;/returns&gt;
      protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
      {
          if (controllerType == null)
          {
              controllerType = typeof(HomeController);
          }
  
          return (IController)this.container.Resolve(controllerType);
      }
  
      #endregion
  }
  </code></pre>