Castle Windsor - IoC registration for open generic interfaces?
13,641
It's called open generic, and yes, Windsor does support that.
container.Register(Component
.For(typeof(IAdapterFactory<,>))
.ImplementedBy(typeof(AdapterFactory<,>))
.LifestylePerWebRequest());
Author by
goldfinger
Updated on June 03, 2022Comments
-
goldfinger about 2 years
Does Castle Windsor permit registration of an open generic interface or do I need to register each possible typed instance separately?
Example - the below with types T,Z fails upon compilation unless I separately specify T, Z with strong types.
container.Register(Component .For<IAdapterFactory<T,Z>>() .ImplementedBy<AdapterFactory<T,Z>>() .LifeStyle.PerWebRequest);
-
goldfinger almost 12 yearsOne word: wow. Thank you! Just out of curiosity, wonder why Castle folks decided to deviate from more standard C# syntax - <T,Z> instead of <,>?
-
Krzysztof Kozmic almost 12 yearsThis is the only syntax that will work in this scenario and it has noting to do with Windsor. This just is how you obtain an instance of
System.Type
representing an open generic type. -
Richard Bailey over 3 yearsProbable the fifth time this answer helped me out 🙄 - thank you