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:
<link rel="stylesheet" type="text/css" href="non-existing.css"/>
Or a link to an image that does not exist. Why is this happening?
My windows class:
public class WindsorControllerFactory : DefaultControllerFactory
{
#region Constants and Fields
/// <summary>
/// The container.
/// </summary>
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
/// <summary>
/// Initializes a new instance of the <see cref="WindsorControllerFactory"/> class.
/// </summary>
public WindsorControllerFactory()
{
// Instantiate a container, taking configuration from web.config
this.container = InversionOfControl.Container;
// Also register all the controller types as transient
IEnumerable<Type> 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
/// <summary>
/// The get controller instance.
/// </summary>
/// <param name="requestContext">
/// The request context.
/// </param>
/// <param name="controllerType">
/// The controller type.
/// </param>
/// <returns>
/// Resolved controller instance.
/// </returns>
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
controllerType = typeof(HomeController);
}
return (IController)this.container.Resolve(controllerType);
}
#endregion
}