I’ve modified my WindsorControllerFactory to throw HttpException 404 when the requested controller doesn’t exist
but I’m not sure if this is a good way of doing this, anybody knows if there can be any problems with this ?
public class WindsorControllerFactory : DefaultControllerFactory
{
readonly IWindsorContainer container;
public WindsorControllerFactory(IWindsorContainer container)
{
this.container = container;
var controllerTypes =
from t in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IController).IsAssignableFrom(t)
select t;
foreach (var t in controllerTypes)
container.Register(Component.For(t).LifeStyle.Transient);
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
//if (controllerType == null) return null;
if (controllerType == null) throw new HttpException(404, "page not found");
return (IController)container.Resolve(controllerType);
}
}
As always a good place to start for this sort of thing is in the Windsor Wiki see http://stw.castleproject.org/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx