Reputation: 56869
I am looking for a convention-based way to replace the following line in my StructureMap registry:
this.For<IMyFactory<ItemList, int>>().Use(x => x.GetInstance<GenericMyFactory<ItemList, int>>());
Clarification
What I am after is a way to auto-register IMyFactory in a way that a concrete instance will be created with the same types in the same order as the interface declaration. The way I have declared above works for ItemList / int combination only - what I want is a way to do it with any combination of types.
I found this method on other SO posts, which seems to work great when there is only 1 type to be supplied, but I can't seem to find one that will work when more than 1 type is generic. The following gives a compile error in my case.
this.Scan(x =>
{
x.TheCallingAssembly();
x.AddAllTypesOf(typeof(IMyFactory<>));
x.WithDefaultConventions();
});
Sources:
StructureMap Auto registration for generic types using Scan
Structuremap and generic types
Upvotes: 1
Views: 451
Reputation: 172716
You can register open generic types in StructureMap as follows:
For(typeof(IMyFactory<,>)).Use(typeof(GenericMyFactory<,>)));
Upvotes: 2