我想将Agatha与StructureMap 3.0包装器的实现一起使用到Agatha的IoC容器中。Agatha有带有NuGet 2.6的StructureMap包,我不喜欢它。
我从从Agatha.StructureMap 源代码复制/粘贴代码开始,然后进行更改以使用3.0StructureMap。
我现在的问题是我得到了一个StructureMapException
StructureMap.StructureMapBuildPlanException occurred
_HResult=-2146233088
_message=Unable to create a build plan for concrete type Agatha.Common.WCF.RequestProcessorProxy
HResult=-2146233088
IsTransient=false
Message=Unable to create a build plan for concrete type Agatha.Common.WCF.RequestProcessorProxy
new RequestProcessorProxy(InstanceContext, String endpointConfigurationName, String remoteAddress)
┗ InstanceContext = **Default**
String endpointConfigurationName = Required primitive dependency is not explicitly defined
String remoteAddress = Required primitive dependency is not explicitly defined
Source=StructureMap
Context=new RequestProcessorProxy(InstanceContext, String endpointConfigurationName, String remoteAddress)
┗ InstanceContext = **Default**
String endpointConfigurationName = Required primitive dependency is not explicitly defined
String remoteAddress = Required primitive dependency is not explicitly defined
Title=Unable to create a build plan for concrete type Agatha.Common.WCF.RequestProcessorProxy
StackTrace:
at StructureMap.Pipeline.ConstructorInstance`1.ToBuilder(Type pluginType, Policies policies) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Pipeline\ConstructorInstance.cs:line 83
InnerException: 在我看来,构造函数StructureMap似乎认为它需要使用,但是视图没有正确配置,是具有多个参数的构造函数。实际上,我需要它使用无参数构造函数。
但是,我认为我已经正确地配置了构造函数。下面是用于为RequestProcessorProxy配置无参数构造函数的代码:
structureMapContainer.Configure(x => x.ForConcreteType<RequestProcessorProxy>().Configure.SelectConstructor(() => new RequestProcessorProxy()));可能出了什么问题?
当我提醒你的时候,我对StructureMap和Agatha都很陌生,所以我可能误解了以上的任何或全部。
发布于 2015-04-07 10:09:14
我从未使用过SelectConstructor,所以不知道如何使用它,但是如果您想让SM使用无参数构造函数,那么在解析具体类型时可以这样做:
var container =
new Container(
c => c.For<RequestProcessorProxy>().Use(() => new RequestProcessorProxy()));或者像这样,当您通过接口解析它时:
var container =
new Container(
c => c.For<IRequestProcessor>().Use(() => new RequestProcessorProxy()));我根本不熟悉Agatha,所以我不知道我是否使用了良好的界面。
希望这能有所帮助!
https://stackoverflow.com/questions/29434324
复制相似问题