A lightweight attribute-based service registration library for .NET. Automatically discovers and wires services into the Microsoft.Extensions.DependencyInjection container by scanning assemblies for classes decorated with [Service], reducing boilerplate and improving maintainability.
- .NET 8.0, 9.0, or 10.0
dotnet add package Equibles.Core.AutoWiringusing Equibles.Core.AutoWiring;
using Microsoft.Extensions.DependencyInjection;
// Registers as itself with Scoped lifetime (default)
[Service]
public class OrderProcessor { }
// Registers as INotificationService with Singleton lifetime
[Service(ServiceLifetime.Singleton, typeof(INotificationService))]
public class EmailNotificationService : INotificationService { }
// Registers without replacing existing registrations
[Service(ServiceLifetime.Transient, typeof(INotificationService), replaceExisting: false)]
public class SmsNotificationService : INotificationService { }using Equibles.Core.AutoWiring;
var builder = WebApplication.CreateBuilder(args);
// Scan the assembly containing Program for [Service] classes
builder.Services.AutoWireServicesFrom<Program>();
var app = builder.Build();
app.Run();The AutoWireServicesFrom<T>() method scans the assembly containing T and registers all classes decorated with [Service].
| Parameter | Type | Default | Description |
|---|---|---|---|
lifetime |
ServiceLifetime |
Scoped |
The DI lifetime (Singleton, Scoped, Transient) |
interfaceType |
Type |
null |
The service type to register as. If null, registers as the concrete class itself |
replaceExisting |
bool |
true |
If true, removes any existing registration for the same service type before adding |
For projects with multiple assemblies, add a marker class to each assembly and call AutoWireServicesFrom for each:
// In each assembly, add an empty marker class
public class MyAssemblyMarker { }
// In Program.cs
builder.Services.AutoWireServicesFrom<MyAssemblyMarker>();
builder.Services.AutoWireServicesFrom<AnotherAssemblyMarker>();Daniel Oliveira