Interview frequency: …
Short answer
Register the open interface type and open implementation without specifying a type argument, with typeof(IRepository<>) and typeof(Repository<>), so the container can construct closed types automatically.
Explanation
Instead of individually registering IRepository<User> and IRepository<Order> for hundreds of tables, register typeof(IRepository<>). When a Controller requests IRepository<User>, the CLR creates a closed Repository<User> instance automatically, reducing repetitive code and allowing a flexible Repository architecture.
Code example
// Registration Open Generic
builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
// Usage: the container automatically injects Repository<Product>
public class ProductController(IRepository<Product> repo) { ... }Common mistakes
- Registering closed generic types and expecting the container to handle all other entities automatically.