mappingstructureopen-generics

Structuremap WhatDoIHave says I have it. ObjectFactory says I don't


Jeez louise, I'm trying to retro fit a plague ridden legacy app with SM and running into all sorts of strangeness. So I apologize for all the strange questions.

so I have this code

var whatDoIHave = ObjectFactory.Container.WhatDoIHave();
var validator = ObjectFactory.GetInstance<IValidator<ProfileActivityElement>>();

the what do I have has this

IValidator`1<ProfileActivityElement> (IValidator`1<ProfileActivityElement>)                                                                                                                                                                                                                                                                                                                                                                                                                                                          
Scoped as:  Transient
4b774bc1-b46e-4fc1-95f4-348bb3786dc8   
Configured Instance of HSTM.HLC.BusinessLogic.Validators.ProfileActivityElememntValidator, HSTM.HLC.BusinessLogic, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3              
                                                                                                                                       29c5ff3e-73bd-44bb-9fc8-5a81fa640499                                                                                                                                                Configured Instance of HSTM.HLC.BusinessLogic.Validators.ProfileActivityElememntValidator, HSTM.HLC.BusinessLogic, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3   

the validator gets an error like this

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily     HSTM.HLC.BusinessLogic.IValidator`1[[HSTM.HLC.BusinessLogic.HCC.ProfileActivityElement,     HSTM.HLC.BusinessLogic, Version=13.1.28.895, Culture=neutral,     PublicKeyToken=0ecfe41405c30fb3]], HSTM.HLC.BusinessLogic, Version=13.1.28.895,     Culture=neutral, PublicKeyToken=0ecfe41405c30fb3

That's the full error, no inner errors. Perhaps I'm just overlooking some syntax error. Thanks for the help, Raif


Solution

  • So the problem here is that I am using ConnectImplementationsToTypesClosing() to register my open generics. Strangely this works fine in some other apps I have but in this app, which as mentioned is legacy and messy, it does not. In fact it registers the open generics as pluginLibraries but they do not end up in the profile _instances so when you ask for them they are not there. That is why they show up in what do I have but not when I ask for them.

    The fix was provided to me by the eminent Kevin M who's last name I have forgotten. I implemented it and presto my app was working again.

    Kevin's Fix

    Thanks Kevin