I am new to implementing the Repository Pattern in my .NET projects and there's this thing that doesn't add up for me. As per my understanding, implementing this pattern requires me to register the "IRepository" interfaces via dependency injection so I can use them in my controllers. Assuming that I have an ICustomerRepository with its concrete implementation CustomerRepository, I should register it like so:
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
}
This is great of course, but what if I have like 50 or more repositories to register? That will result in a pretty messy Program class, don't you think?
Since all the concrete implementations of the interfaces inherit from a GenericRepository, is there a way to register all of them at once? This is what I mean in pseudo-code:
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<(all the I{Entity}Interfaces),
(all those concrete classes that inherit from GenericRepository)>();
}