StructureMap 202 - 为什么?

时间:2010-01-28 16:57:29

标签: structuremap interceptor

好的,我正在尝试在我注册SM的类型上设置属性。

这是我的一个组件中注册表的代码。这个 在配置期间从控制台应用程序添加注册表。 当我尝试访问实例的EndorsementSpecs属性时 AutoMandatoryEndorsementAggregator对象,我得到了202.什么的 有趣的是我可以打电话 来自我的GetAllInstances>() 控制台应用程序,它解决得很好。有什么关于 从OnCreation中访问此代码导致202?一世 可以在WhatDoIHave()中看到我期望的一切。我也尝试了一个具有相同结果的TypeInterceptor。

//register all open generics
cfg.ConnectImplementationsToTypesClosing(typeof
(MandatoryEndorsementSpecBase<>));

ForSingletonOf<IMandatoryEndorsementAggregator<AutoPolicy>>()
                    .Use<AutoMandatoryEndorsementAggregator>()
                    .OnCreation((context, x) =>
                    {

                        var specs =
context.GetAllInstances<MandatoryEndorsementSpecBase<AutoPolicy>>();
                        x.EndorsementSpecs = specs;
                    })
                    ; 

1 个答案:

答案 0 :(得分:0)

很抱歉转移您的真实问题,但您是否只是想将所有MandatoryEndorsementSpecBase实例注入AutoMandatoryEndorsementAggregatory? 如果是这样,你可以放弃它只是使它成为一个构造函数参数,以便它们都被自动注入。

public AutoMandatoryEndorsementAggregatory(MandatoryEndorsementSpecBase<AutoPolicy>[] endorsementSpecs){
  EndorsementSpecs = endorsementSpecs;
}