Register all classes in one statement?


I understand that by applying a type of a service in the constructor of AppHostBase it is registering all the Services in this assembly (constructor injection).

I have a separate assembly/project with all my Repositories inside. These needs the IDbConnectionFactory injected in their constructor. Is there a way to register all of these repositories in one go. Now I do the following in the Configure method of the AppHostBase:

container.RegisterAs<Repositories.CampaignRepository, Repositories.Interfaces.ICampaignRepository>();
container.RegisterAs<Repositories.SearchRepository, Repositories.Interfaces.ISearchRepository>();
container.RegisterAs<Repositories.ClientRepository, Repositories.Interfaces.IClientRepository>();

Thanks for your advice!

There isn’t anything generic built-in, the only scanning and auto registration of dependencies like this is when registering all validation filters in an assembly:

//This method scans the assembly for validators

The code to do this is in ValidationExtensions although it’s tailored specifically for IValidator<T> you should be able to do something similar for your repositories.