C# Concepts 5
C# Concepts 5
Generics
C#: Generics
// Register in DI container
builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
Generic Repository - Benefits
• Code Reusability: Single repository implementation for multiple
entities.
Explanation:
• T must be a reference type (class).
• T must implement IEntity.
• T must have a parameterless constructor (new()).