Traditionally, we register multiple services, multiple interfaces under ConfigureServices method in the Startup class. This is feasible if we have five or ten registrations. But what if we have fifty or more such registrations?
public void ConfigureServices(IServiceCollection services) {
service.AddTransient<ISQLDB, SQLDB>();
service.AddTransient<IEmployeeBusiness, EmployeeBusiness>();
service.AddTransient<IEmployeeRepository, EmployeeRepository>();
service.AddTransient<IEmployeeValidation, EmployeeValidation>();
service.AddTransient<IDepartmentBusiness, DepartmentBusiness>();
service.AddTransient<IDepartmentRepository, EmployeeRepository>();
service.AddTransient<IDepartmentValidation, EmployeeValidation>();
...
...
...
// some 50 or more
}
I want to move the registering part to another custom InjectDependency class and call this in ConfigureServices method like:
public class InjectDependency{
public InjectDependency(IServiceCollection service)
{
service.AddTransient<ISQLDB, SQLDB>();
service.AddTransient<IEmployeeBusiness, EmployeeBusiness>();
service.AddTransient<IEmployeeRepository, EmployeeRepository>();
service.AddTransient<IEmployeeValidation, EmployeeValidation>();
service.AddTransient<IDepartmentBusiness, DepartmentBusiness>();
service.AddTransient<IDepartmentRepository, EmployeeRepository>();
service.AddTransient<IDepartmentValidation, EmployeeValidation>();
...
...
...
...
}
}
Is there any way to achieve this?