A lightweight .NET dependency injection extension library that supports automatic service registration via attributes.
- Attribute-based registration: Mark classes with
[Singleton],[Scoped], or[Transient]attributes - Interface support: Register services with one or multiple interface types
- Keyed services: Support for keyed service registration (requires .NET 8+)
- Generic attributes: Convenient generic attribute syntax (requires .NET 8+)
dotnet add package VoidNone.DependencyInjection[Singleton]
class DatabaseService { }
[Scoped]
class UserService { }
[Transient]
class LoggerService { }services.AddFromAssemblies(typeof(Service1).Assembly);| Attribute | Description |
|---|---|
[Singleton] |
Single instance for the lifetime of the application |
[Scoped] |
One instance per request/scope |
[Transient] |
New instance each time it's requested |
interface IService { }
interface IBaseService { }
[Singleton<IService>]
class MyService : IService { }
// Register with multiple interfaces
[Singleton<IService, IBaseService>]
class MyService2 : IService, IBaseService { }[Singleton<IService>("primary")]
class PrimaryService : IService { }
[Singleton<IService>("backup")]
class BackupService : IService { }var provider = services
.AddFromAssemblies(typeof(MyService).Assembly)
.BuildServiceProvider();
// AddFromAssemblies registers the IServiceCollection itself so metadata helpers can inspect it later
// Get all implementation types for a service
Type[] types = provider.GetAllServiceTypes<IService>();
// Get all service instances (including keyed services) (.NET 8+)
IEnumerable<IService> instances = provider.GetAllServices<IService>();MIT