views:

66

answers:

1

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;
                    })
                    ; 
A: 

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;
}
Joshua Flanagan
This is actually what I ended up doing and it works, as I knew it would, but there are cases where doing something like this makes sense (otherwise this functionality wouldn't exist), so at some point I'll likely have to deal with figuring out what is going wrong.
Corey Coogan