Unity: Register and resolve class with generic type
T may be any type. I want to be able to create instances of ICollectionWrapper without having to register every possible combination of T.
That's what register generics is for. Some IOC name the method as RegisterGeneric
to make it self explanatory (autofac for example), but unity keep it just an overload of RegisterType
.
container.RegisterType(typeof(ICollectionWrapper<>), typeof(CollectionWrapper<>), new TransientLifetimeManager());
Also note that your injectable is having multiple constructors. That itself is considered as anti-pattern.
If you fix the multiple construtor thing, above registration will work.