![](/img/trans.png)
[英]Expression of type 'System.Func`2[T,System.Boolean]' cannot be used for return type 'System.Boolean'
[英]ServiceStack/Funq cannot resolve System.Boolean exception
我已经使用内置的Funq IoC容器设置了ServiceStack api来解析我的存储库。 但是,当我调用api方法时,出现以下异常:
无法解析类型为System.Boolean的必需依赖项。
上一次我检查System.Boolean不需要任何解决。 我已经在AppHost Configure中注册了我的存储库,如下所示:
container.RegisterAutoWiredAs<OrganisationRepository, IOrganisationRepository>().ReusedWithin(ReuseScope.Request);
这是我第一次使用ServiceStack或Funq。 我做错什么了吗? 有没有解决的办法?
如果使用container.RegisterAutoWiredAs<T,IT>()
则Funq将按照约定自动连接存储库,即使用最大的构造函数并解析并注入存储库的每个公共属性依赖项。
要使用替代的特定构造函数,或仅使用自动装配特定的属性,您必须使用以下方法手动指定注册:
container.Register<IOrganisationRepository>(c =>
new OrganisationRepository(c.Resolve<IFoo>()) { Bar = c.Resolve<IBar>() } );
注意:每当遇到类似IOC的问题时,还应包括课程的框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.