Hi guys
Wanted to ask a quick question regarding castle windsor and implementing IoC for Controllers in Areas. Does Castle 2.5 support MVC 2.0 areas?
My Castle config works ok for my root controller in the root of my site but any area controllers are not found with a
The IControllerFactory 'XXX.Castle.WindsorControllerFactory' did not return a controller for the name 'Registration'.
I am using Castle directly not through MvcContrib
Code as follows:
class WindsorControllerFactory : DefaultControllerFactory
{
WindsorContainer container;
// The constructor:
// 1. Sets up a new IoC container
// 2. Registers all components specified in web.config
// 3. Registers all controller types as components
public WindsorControllerFactory()
{
// Instantiate a container, taking configuration from web.config
container = new WindsorContainer();
// Also register all the controller types as transient
var controllerTypes =
from t in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IController).IsAssignableFrom(t)
select t;
foreach (Type t in controllerTypes) {
//container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
container.Register(Component.For(t).Named(t.FullName).LifeStyle.Transient);
}
container.Install(new WindsorInstaller());
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType != null)
{
return (IController)container.Resolve(controllerType);
}
return null;// base.GetControllerInstance(requestContext, controllerType);
}
}
Many thanks
Richard