Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.1 KB

Readme.md

File metadata and controls

42 lines (31 loc) · 1.1 KB

FastInject

Easy and fast way to inject your services into DI container of your application.

How to use it

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));

Example

[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;
	}

}