Learn
Learn Ark DI
Understand immutable registration, contextual resolution, scopes, ownership, async initialization, and teardown.
Learn Ark DI
Ark DI is a pure-Dart object-graph runtime. It owns composition mechanics, not business behavior and not a hidden global access point.
Start with the problem
An application must create objects in dependency order: configuration before an API client, the client before a Repository, and the Repository before a service or UseCase. Some objects are shared, some are transient, some initialize asynchronously, and some must be disposed in the reverse order. Tests and feature previews may also need bounded replacements without mutating the production graph.
Ark DI records those construction and lifecycle rules in one immutable container:
Composition Root registers construction rules
↓
Resolver creates or returns a dependency according to its strategy
↓
child Scope may provide explicit local overrides
↓
close waits for active resolution and disposes owned objects in dependency order
Application classes should still use constructor injection. The container belongs at composition boundaries; ordinary domain and application code does not retrieve it.
Choose a registration by lifetime
| Need | Registration |
|---|---|
| Existing object with explicit owner | Instance |
| New short-lived object for every request | Factory |
| One object created on first use | Lazy Singleton |
| New asynchronous object for every request | Async Factory |
| One shared asynchronously initialized object | Async Lazy Singleton |
Recommended path
- Getting started builds and closes a small graph.
- Composition Root explains where concrete types are connected.
- Registrations and ownership separates acquisition from lifecycle responsibility.
- Scopes and overrides defines hierarchy and local-first resolution.
- Async resolution covers deterministic access, retries, and shared in-flight initialization.
- Lifecycle and teardown explains active leases and reverse dependency order.
Flutter integration is a separate branch backed by ark_di_flutter.
Ark DI does not require a single application-wide Singleton container. A root Scope is available for applications that need it, while feature, session, preview, and test Scopes keep shorter lifetimes explicit.