I'm getting the 'No parameterless constructor defined for this object' on my controller when the controller and its dependencies are being registered accordingly via (DI/IoC) pattern using Castle Windsor. Can someone take a look at the following and see my error because i can't see it.
Code for registration on global.asax
public class MyApplication : System.Web.HttpApplication
{
public MvcApplication()
{
this.container = new WindsorContainer().Install(new DependencyInstaller());
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
new WindsorActivator(this.container));
}
}
My DI
public class DependencyInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IDatabaseFactory>().ImplementedBy<DatabaseFactory>().LifeStyle.PerWebRequest,
Component.For<IUnitOfWork>().ImplementedBy<UnitOfWork>().LifeStyle.PerWebRequest,
Component.For<IMappingEngine>().ImplementedBy<MappingEngine>().UsingFactoryMethod(() => Mapper.Engine).LifeStyle.Singleton,
Component.For<IFirmTasks>().ImplementedBy<FirmTasks>().LifeStyle.PerWebRequest,
Classes.FromAssemblyContaining<PersonController>().BasedOn<IController>().LifestyleTransient(),
Classes.FromThisAssembly().BasedOn<IHttpController>().LifestyleTransient(),
Classes.FromAssemblyNamed("Core.Firm.Tasks").Where(type => type.Name.EndsWith("Tasks")).WithServiceAllInterfaces().LifestylePerWebRequest(),
Classes.FromAssemblyNamed("Core.Firm.Repository")
.Where(type => type.Name.EndsWith("Repository")).WithServiceAllInterfaces().LifestylePerWebRequest()
);
}
}
my controller
public class PersonController : Controller
{
private IFirmTasks tasks;
public PersonController(IFirmTasks tasks)
{
this.tasks = tasks;
}
When I load the application the container loads fine with all dependencies resolved as per screen shot on debug.
Anyone out there got any idea's where my failings lie. Thanks in advance.