I need to register open generic of a type in my Windsor Container. How does this thing works?
container.Register(Component.For<IRepository<??>>().UsingFactoryMethod(x => x.Resolve<IDataContext>().GetRepository<??>()));
Basically, I want to register IRepository as open generic and then create the repository from the IDataContext based on the passed generic type. Is this supported?
When registering open generic use non-generic method:
When resolving via
UsingFactoryMethodyou can have access to the type that is requested, so you can pass the type to yourGetRepositoryand resolve the repository based on the type (System.Type object) you pass.As a sidenote I must say I find your design rather unusual. It’s more common that a repository holds a reference to data context, not the other way around. Perhaps you’d want to take another look at the design instead?