Put [Scoped] on a class. AutoWire writes the services.AddScoped<…>() line for you at build time, and tells you before you run when your DI graph is wrong.
- No reflection, no assembly scanning. Plain generated code, so it works with Native AOT and trimming (checked on every build).
- DI mistakes become build errors and IDE warnings — captive dependencies, circular dependencies, missing registrations, wrong service types — most with a one-click fix.
- Migrate in one command from Scrutor, Autofac or hand-written
AddScopedlines. - Runs on any .NET 8 SDK or later (Visual Studio 2022 17.8+).
dotnet add package AutoWire// Before: Program.cs grows forever, and breaks when someone forgets a line
builder.Services.AddScoped<IOrderService, OrderService>();
builder.Services.AddSingleton<ICache, RedisCache>();
builder.Services.AddTransient<IReportGenerator, PdfReportGenerator>();
// ... 40 more lines// After: the registration lives next to the class
[Scoped] public class OrderService : IOrderService { }
[Singleton] public class RedisCache : ICache { }
[Transient] public class PdfReportGenerator : IReportGenerator { }
// Program.cs: one line, forever
builder.Services.AddAutoWireServices(); // using AutoWire;The generated code is ordinary IServiceCollection calls in obj/ — exactly what you would have written by hand.
[Singleton]
public class ReportingService(IOrderService orders) { }
// ⚠ AW004: Singleton 'ReportingService' depends on Scoped service 'IOrderService'
// (captive dependency). Quick fix: inject IServiceScopeFactory.| ID | What it catches |
|---|---|
| AW003 ❌ | [Scoped(typeof(IFoo))] on a class that doesn't implement IFoo |
| AW004 / AW009 ⚠ | Singleton or hosted service capturing a scoped service |
| AW013 ⚠ | Constructor needs a service nobody registered |
| AW016 ❌ | Circular dependency between services |
| AW006 / AW008 ⚠ | Disposable transients; singletons holding DbContext or IHttpContextAccessor |
All 26 diagnostics and their fixes →
| Scrutor | Injectio | AutoWire | |
|---|---|---|---|
| Registration happens | at startup (reflection) | at build time | at build time |
| Native AOT / trimming | ✗ | not stated | ✓ verified in CI |
| Decorators (incl. open generic) | ✓ | ✓ | ✓ |
| Build-time checks for captive, circular and missing dependencies | ✗ | not stated | ✓ with code fixes |
| Automated migration from Scrutor / Autofac | — | — | ✓ |
| Minimum toolchain | any | Roslyn 4.14 (VS 17.14 / .NET 9.0.300 SDK) | .NET 8 SDK / VS 17.8 |
Based on each project's own documentation, November 2026. Corrections welcome via an issue.
dotnet tool install --global Swevo.AutoWire.Migrator
autowire-migrate --path . # report only
autowire-migrate --path . --apply # rewrite safe cases to attributesIt understands Scrutor Scan(...)/Decorate(...), Autofac RegisterType/RegisterAssemblyTypes/RegisterDecorator, and plain AddScoped/AddSingleton/AddTransient, and rates each finding AutoConverted, NeedsReview or Manual. In the IDE, AW018 and AW026 offer the same migration as quick fixes. Migration guide →
- Lifetimes:
[Scoped],[Singleton],[Transient], andTry*variants for library authors — reference - Keyed services with string or enum keys — reference
- Decorators with ordering, including open-generic decorators — reference
- Open generics —
Repository<T> : IRepository<T>— reference - Convention scanning by namespace, and other assemblies — reference
- Profiles, conditions and modules for per-environment and opt-in registration — reference
- Factories, hosted services, options binding, typed HttpClients, FluentValidation validators — reference
- Compile-time interceptors (AOP without Castle) and minimal API endpoints — reference
- Registration manifest and Mermaid dependency graph for CI diffs and docs — reference
- Test helpers —
services.OverrideService<IFoo, FakeFoo>()— reference
- Build: .NET 8 SDK or later, Visual Studio 2022 17.8+ or Rider 2023.3+.
- App: anything using
Microsoft.Extensions.DependencyInjection— ASP.NET Core, Worker Services, MAUI, Blazor, console. Targetsnet6.0+ andnetstandard2.0+. Keyed services need DI 8.0+. - AutoWire adds nothing to your output: it ships only a source generator and analyzers.
- Full reference — every attribute, option and diagnostic
- Samples — Web API and Worker Service
- Changelog
- Scrutor comparison and benchmark — registration is ~17× faster than Scrutor's runtime scanning
Made by Justin Bannister, who also writes other compile-time .NET libraries and consults on Polly v8 resilience, Azure architecture and clean .NET design: solidqualitysolutions.com · LinkedIn.
MIT © Justin Bannister