Easy and fast way to inject your services into DI container of your application.
Every service you want to inject just needs to use the Inject
attribute,
with ServiceLifetime
to insert into your DI container.
[Inject(ServiceLifetime.Singleton)]
public class SomeServie : ISomeService {
// ...
}
Now just configure it at once in your DI.
services.InjectAllFromRootType(typeof(Program));
[Inject(ServiceLifetime.Singleton)]
public class SomeServie : ISomeService {
// ...
}
public static class DependencyInjector {
public static IServiceCollection AddPresentation(this IServiceCollection services) {
// All services flagged with the Inject attribute will be registered
services.InjectAllFromRootType(typeof(DependencyInjector));
// Now every service with Inject attribute in same namespace of DependencyInjector class will be inserted automatically into DI container.
return services;
}
}