StructureMap - Scan - Generic Interface with base implementation and specific.

Posted by Morten Schmidt on Stack Overflow See other posts from Stack Overflow or by Morten Schmidt
Published on 2010-04-12T08:16:10Z Indexed on 2010/04/12 8:23 UTC
Read the original article Hit count: 853

Filed under:
|

Hi

I have an interface something like this:

interface IGenericSetupViewModel<T>

I then have a default implemtation of this, something like this

class GenericSetupViewModel<T> : IGenericSetupViewModel<T>

For some specific classes i have a specific implementation like this:

class ContractSetupViewModel : GenericSetupViewModel<Contract>

Now i want to make StructureMap return the correct instance, when asking for a

ObjectFactory.GetInstance<GenericSetupViewModel<Contract>();

I would like to get ContractSetupViewModel returned, when asking for anything else, i would like to get an instance of

GenericSetupViewModel<T>

I tried doing this:

        StructureMap.ObjectFactory.Configure(x =>
        {
            x.Scan(y =>
            {
                y.TheCallingAssembly();
                y.AddAllTypesOf(typeof(IGenericSetupViewModel<>));
                y.ConnectImplementationsToTypesClosing(typeof(IGenericSetupViewModel<>));
            });
        });

However this results in me always getting a GenericSetupViewModel and never the ContractSetupViewModel. I dont want to have to specify all specific viewmodels so is there anyway i can get this scan to work ?

© Stack Overflow or respective owner

Related posts about structuremap

Related posts about c#