1

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?

Carvellis
  • 3,992
  • 2
  • 34
  • 66
  • 1
    You can't automatically resolve something that takes a boolean parameter. How would it know whether to pass `true` or `false`? – SLaks Dec 31 '12 at 14:29
  • None of my constructors get a boolean value. The exact same setup works using Autofac. – Carvellis Dec 31 '12 at 14:32
  • @SLaks ah there actually was one dependency with an overloaded constructor that takes a boolean value. The same dependency always worked with Autofac because probably Autofac is smart enough to find the constructor (without the boolean parameter) that it can actually resolve. – Carvellis Dec 31 '12 at 14:47

1 Answers1

2

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.

mythz
  • 141,670
  • 29
  • 246
  • 390