I am using StructureMap.MVC5 and have the following projects and classes:
Web
HomeController(PageService pageService)
Services
PageService(IPageRepository pageRepository)
Repositories
PageRepository : IPageRepository
IRepositories
IPageRepository
With the default implementation of StructureMap.MVC5 it automatically resolves the PageService into my HomeController, but not PageRepository into my PageService. This gives me the exception: No parameterless constructor defined for this object.
This is solved by adding a line to DefaultRegistry:
For<IPageRepository>().Use<PageRepository>();
But obviously I would rather have StructureMap automatically resolve this. Is there a way to achieve that?
This is what the DefaultRegistry looks like:
public DefaultRegistry()
{
Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
}