【问题标题】:Agatha RRSL and StructureMap 3.0Agatha RRSL 和 StructureMap 3.0
【发布时间】:2015-06-08 16:04:20
【问题描述】:

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

我首先从 Agatha.StructureMap source code 复制/粘贴代码,然后进行更改以使用 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 都是新手,所以我可能误解了上述任何或所有内容...

【问题讨论】:

    标签: structuremap agatha-rrsl


    【解决方案1】:

    我从未使用过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完全不熟悉,所以不知道我是否使用了好的界面。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多