I'm using Ninject.MVC3
for my DI
.
I have more than 25 dependencies to inject, but my RegisterService
now has 25 lines with simlar code like:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IClientRepository>().To<ClienteRepository>();
kernel.Bind<IRegionRepository>().To<RegionRepository>();
kernel.Bind<IRequestTypeRepository>().To<SolicitudTipoRepository>();
kernel.Bind<OrdenRepository>().To<OrdenRepository>();
//Some other references....
}
But, is possible create a generic repository (or repository interface) to inherit all my repos and only inject a generic class?
well one way to do it is doing a query your assemblies by interface and implementation using reflection, you have to define which namespaces you would like to scan something like:
that way you are implementing convention over configuration and you'll avoid doing registrations one by one, it could be other ways but this strategy can be applied to any container you want to use.