简体   繁体   English

ServiceStack / Funq无法解决System.Boolean异常

[英]ServiceStack/Funq cannot resolve System.Boolean exception

I've setup a ServiceStack api using the built-in Funq IoC container to resolve my repositories. 我已经使用内置的Funq IoC容器设置了ServiceStack api来解析我的存储库。 However, when I call an api method, I get the following exception: 但是,当我调用api方法时,出现以下异常:

Required dependency of type System.Boolean could not be resolved. 无法解析类型为System.Boolean的必需依赖项。

Last time I checked System.Boolean didn't require any resolving. 上一次我检查System.Boolean不需要任何解决。 I've registered my repositories in the AppHost Configure as follows: 我已经在AppHost Configure中注册了我的存储库,如下所示:

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

This is my first time using ServiceStack or Funq. 这是我第一次使用ServiceStack或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. 如果使用container.RegisterAutoWiredAs<T,IT>()则Funq将按照约定自动连接存储库,即使用最大的构造函数并解析并注入存储库的每个公共属性依赖项。

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. 注意:每当遇到类似IOC的问题时,还应包括课程的框架。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“System.Func`2[T,System.Boolean]”的表达式不能用于返回类型“System.Boolean” - Expression of type 'System.Func`2[T,System.Boolean]' cannot be used for return type 'System.Boolean' Visual Studio 2012无法将&#39;bool&#39;转换为&#39;System.Boolean&#39; - Visual Studio 2012 cannot convert from 'bool' to 'System.Boolean' 无法返回null(System.Boolean不能为null) - Can't return null (System.Boolean cannot be null) 如何使用ServiceStack Funq IoC解析类型 - How to resolve type using ServiceStack Funq IoC 亚超音速3-无法将类型为&#39;System.UInt64&#39;的对象转换为类型为&#39;System.Boolean&#39; - Subsonic 3 - Object of type 'System.UInt64' cannot be converted to type 'System.Boolean' 无法在System.Boolean上测试 - Can't test on System.Boolean 如何使用ServiceStack和Funq.Container解析ILog - How can I resolve ILog using ServiceStack and Funq.Container 无法将null值分配给类型为System.Boolean的成员,该类型是不可为空的值类型 - The null value cannot be assigned to a member with type System.Boolean which is a non-nullable value type 无法将属性“X”中的字符串“False”转换为“System.Boolean”类型的对象 - Cannot convert string 'False' in attribute 'X' to object of type 'System.Boolean' “范围&#39;&#39;引用的&#39;System.Boolean&#39;类型的”变量“,但未在Expression中定义 - “variable '' of type 'System.Boolean' referenced from scope '', but it is not defined” in Expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM