The async-first dependency injection container for .NET.
Awaiten is a Roslyn source generator that wires your object graph at build time. There is no runtime reflection, the generated code is plain readable C#, and your container is native-AOT clean. The configuration is verified by the compiler: missing, cyclic, ambiguous, and lifetime-mismatched registrations are build errors.
Its headline feature is async initialization. Services that need asynchronous setup after construction, like opening a connection or handshaking with hardware, are tracked through the graph. Reaching one before it is ready is a compile error.
dotnet add package Awaitenusing Awaiten;
public interface IWarmUp // your own interface, no Awaiten reference
{
Task WarmUpAsync(CancellationToken cancellationToken);
}
public sealed class EspressoMachine : IWarmUp
{
public Task WarmUpAsync(CancellationToken cancellationToken) => HeatBoilerAsync(cancellationToken);
}
[Container]
[AsyncInitializer<IWarmUp>(nameof(IWarmUp.WarmUpAsync))] // every IWarmUp is warmed up before use
[Singleton<EspressoMachine>]
[Scoped<Order>]
[Transient<Cup>]
public static partial class CoffeeShop;
await using CoffeeShop.Root shop = new();
await shop.InitializeAsync(); // the espresso machine warms up
Cup cup = shop.Resolve<Cup>();- Async initialization. Services named by an async initializer convention or an asynchronous
OnActivatedhook are initialized in dependency order, and reaching one synchronously is a compile error. - Compile-time safety. More than 100 diagnostics turn wiring mistakes into build errors instead of startup crashes.
- No reflection. The generated code is plain C#, so the container is native-AOT clean and trim-safe.
- A full toolbox. Lifetimes, scopes, keyed services, decorators, composites, open generics, collections, factories, modules, assembly scanning, property injection, and
Owned<T>for disposable transients. - MS.DI interop. A separate package bridges into Microsoft.Extensions.DependencyInjection for ASP.NET Core and the generic host.
| Package | Description |
|---|---|
Awaiten |
The core: attributes, the source generator, and the runtime seams. No third-party dependencies; on netstandard2.0 only Microsoft.Bcl.AsyncInterfaces. |
Awaiten.Extensions.DependencyInjection |
Microsoft.Extensions.DependencyInjection interop (ASP.NET Core, generic host, and other containers). |
Full documentation lives at awaiten.dev.
- Introduction: what Awaiten is, how it compares and when to pick something else
- Getting started
- Complete example and what Awaiten generates for it
- Design principles and the composition root
- Core concepts: lifetimes, scopes, async initialization, lifetime safety, disposal, owned
- Registration: factories and instances, lifecycle hooks, decorators, composites, keyed services, open generics, scanning, modules, extending containers
- Resolution: dependency shapes, resolving services, relationships, collections, keyed dictionaries, property injection, runtime arguments, context-aware factories, generic variance
- Hosting: MS.DI bridge, external services, migrating from MS.DI
- Diagnostics
- Reference: attributes, runtime API, glossary, troubleshooting and FAQ