I have some IoC container (it doesn't matter which one, but lets assume it is Autofac). In my solution I have more than 30 services which need to be registered. All services resides in the same assembly called Services and each class has a name in format {specific_name}Service.cs.
I'd like to avoid for some reasons registering each service manually this way:
container.Register<OneService>().AsSelf();
container.Register<TwoService>().AsSelf();
...
container.Register<ThirtyFourService>().AsSelf();
And register my types in this way:
Type[] serviceTypes = Assembly.Load("Services")
.GetTypes()
.Where(t => t.Name.EndsWith("Service"))
.ToList();
foreach(Type serviceType in serviceTypes)
{
container.Register(serviceType).AsSelf();
}
All I want achive is minimalistic registration process which allows me add or remove services and keep source code clean. Initialization of my application can be slow (server side application), but when first request comes, it has to behave as quick as possible (performance does really matter at serving responses). Saying initialization I mean registering types, reading configuration files, etc.
Does such reflection usage slow my application "at runtime" or just impact app initialization? How dependencies will be resolved later?
Aucun commentaire:
Enregistrer un commentaire