문제

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 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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top