What is Open Generics registration in DI?
Updated Apr 28, 2026
Short answer
Open Generics allow you to register a generic type definition without specifying the type parameters.
Deep explanation
Instead of registering IRepository<User> to Repository<User> and IRepository<Order> to Repository<Order>, you register IRepository<> to Repository<>. The container dynamically creates the correctly typed generic class when requested.
Real-world example
Implementing the CQRS pattern where ICommandHandler<TCommand> maps to various specific command handlers automatically.
Common mistakes
- Trying to register open generics using standard strong-typing methods which cause compiler errors.
Follow-up questions
- Can you constrain open generic registrations?