Question

I've setup a ServiceStack api using the built-in Funq IoC container to resolve my repositories. However, when I call an api method, I get the following exception:

Required dependency of type System.Boolean could not be resolved.

Last time I checked System.Boolean didn't require any resolving. I've registered my repositories in the AppHost Configure as follows:

container.RegisterAutoWiredAs<OrganisationRepository, IOrganisationRepository>().ReusedWithin(ReuseScope.Request);

This is my first time using ServiceStack or Funq. Am I doing anything wrong? Is there a way around this?

Was it helpful?

Solution

If you use container.RegisterAutoWiredAs<T,IT>() then Funq will auto-wire the Repository by convention, i.e. use the largest constructor and resolve and inject each public property dependency of your Repository.

To use an alternate specific constructor, or only autowire specific properties you would have to specify the registration manually with:

container.Register<IOrganisationRepository>(c => 
    new OrganisationRepository(c.Resolve<IFoo>()) { Bar = c.Resolve<IBar>() } ); 

Note: whenever you have IOC issues like this, you should also include the skeleton of your class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top