I'm working in a project that uses both ApiControllers and Controllers (not webapi) with Castle (from Nuget)
internal class WebWindsorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component
.For<RepositoryFactories>()
.ImplementedBy<RepositoryFactories>()
.LifestyleSingleton());
container.Register(Component
.For<IRepositoryProvider>()
.ImplementedBy<RepositoryProvider>()
.LifestylePerWebRequest());
container.Register(Component
.For<IProjUow>()
.ImplementedBy<ProjUow>()
.LifestylePerWebRequest());
container.Register(Classes
.FromAssemblyContaining<Api.CategoriesController>()
.BasedOn<IHttpController>()
.If(t => t.Name.EndsWith("Controller"))
.LifestylePerWebRequest());
container.Register(Classes
.FromAssemblyContaining<CategoriesController>()
.BasedOn<IController>()
.If(t => t.Name.EndsWith("Controller"))
.LifestylePerWebRequest());
}
}
This in global.asax (Application_Start)
var container = new WindsorContainer().Install(new WebWindsorInstaller());
GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container);
And this is the Controller constructor of CategoriesController
public class CategoriesController : ControllerBase
{
public CategoriesController(IProjUow uow)
{
Uow = uow;
}
}
And ControllerBase inherites from Controller
The ApiController is defined as follows:
public abstract class ApiControllerBase : ApiController
{
protected IProjUow Uow { get; set; }
}
public class CategoriesController : ApiControllerBase
{
public CategoriesController(IProjUow uow)
{
Uow = uow;
}
}
The ApiController works ok, but the other one says:
No parameterless constructor defined for this object.
Why?
Thanks in advance! Guillermo.