StructureMap - Scan - Generic Interface with base implementation and specific.
- by Morten Schmidt
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 ?