开发者

StructureMap 202 - Why?

OK, I'm trying to set a property on a type I'm registering with SM.

Here's the code from the registry in one of my components. This registry is being added during the configuration from a console app. When I try to access the EndorsementSpecs property of the instance AutoMandatoryEndorsementAggregator object, I get the 202. What's interesting is that I can call GetAllInstances>() from my console app and it resolves just fine. Is there something about accessing开发者_如何学C this code from within OnCreation that is causing the 202? I can see everything I expect in WhatDoIHave(). I've also tried a TypeInterceptor with the same results.

//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;
                    })
                    ; 


Sorry to deflect your real questions, but are you just trying to inject all instances of MandatoryEndorsementSpecBase into AutoMandatoryEndorsementAggregatory? If so, you can probably get away with just making it a constructor parameter so that they are all automatically injected.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜