简体   繁体   中英

ServiceStack/Funq cannot resolve System.Boolean exception

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?

If you use container.RegisterAutoWiredAs<T,IT>() then Funq will auto-wire the Repository by convention, ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM