1

我想将 Agatha RRSL 与我对 Agatha 的 IoC 容器的 StructureMap 3.0 包装器的实现一起使用。Agatha 有我不喜欢的带有 StructureMap 2.6 的 NuGet 包。

我首先从 Agatha.StructureMap源代码中复制/粘贴代码,然后进行更改以使用 3.0 StructureMap。

我现在遇到的问题是我得到了一个 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 都是新手,所以我可能误解了上述任何或所有内容......

4

1 回答 1

3

我从来没有使用过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 RRSL,所以我不知道我是否使用了好的界面。

希望这可以帮助!

于 2015-04-07T10:09:14.953 回答