Documentation
v0.10.0latestServed live from mjdi/docs/ — the same markdown ships to agents via /api/mcp.
Welcome to the documentation for mjdi, the compile-time-first dependency
injection library for Mojo 1.2.0. Every document in this set describes the
implemented, tested behavior of the library — not a design target. Claims
about compiler behavior are backed by experiments in experiments/ and
cataloged in technical-investigation.md.
The release these documents describe: mjdi 0.10.0 against
mojo 1.2.0 (2016d0cd). See changelog.md for the release
history.
The documentation map
Start here
| Document | What it covers |
|---|---|
| Getting started | Installing Mojo, getting mjdi, your first wired application, running the examples and the test suite. |
| Tutorial | Build a complete application step by step — every provider kind, every lifetime, with verified output at each stage. |
| Core concepts | The vocabulary and the mental model: services, providers, scopes, registries, containers, and the compile-time/runtime split. |
Everyday use
| Document | What it covers |
|---|---|
| Usage guide | The concise practical guide: declaring services, all four provider kinds, scopes, custom construction, the error model. |
| Providers | Deep dive on class, value, factory, and alias providers — semantics, constraints, selection guide. |
| Third-party types | The use_* family: wiring structs you do not own (use_value, use_provider) with every lifetime. |
| Scopes and lifetimes | Transient, singleton, and scoped behavior in full: caching, copies, create_scope(), close_scope(). |
| Dependency declaration | Inject[T] in depth: value(), is_resolved(), cloned(), nested graphs, and the immutable-reference rule. |
| Linear services | @__annotation(mjdi_linear) linear types: construct-in-place, single use through the resolve[T](/docs/0.10.0/visitor) overload, explicit destroy, and the trait-bound/where-clause overloads that keep linear values out of caching lifetimes. |
| Linear resource patterns | Transactions, file leases, lock tokens: the resource-oriented linear patterns with the destruction-diagnostics matrix (P1-21/P1-22). |
| Injectable | The Injectable contract: two-phase construction, requirements, and overriding create(). |
| Lifecycle hooks | The InjectableLifecycle contract: post_construct after wiring, pre_destruct before mjdi releases a cached instance (close() / close_scope()), and the deliberate exclusions. |
| Runtime validation | The value-provider inventory, missing_values, and validate_runtime() — startup checks that never construct a service or run a factory (P1-06/P1-07). |
| Registry overrides | The override / override_value / override_factory family: typed test composition by replacing providers (P1-09). |
| Scope guard | with_scope and ScopeGuard: lexical scope management that makes forgetting close_scope() impossible (P1-13). |
| Container guard | with_container and ContainerGuard: container lifecycle management with exactly-once close() (P1-14). |
| Patterns and best practices | Composition roots, configuration, shared state, ports and adapters under value semantics, anti-patterns. |
| FAQ | Short answers to the questions that come up most often. |
Correctness and errors
| Document | What it covers |
|---|---|
| Compile-time validation | Everything mjdi rejects before your program runs, when the checks fire, and the detection boundaries. |
| Diagnostics | The complete catalog of compile-time errors, runtime raises, and aborts — exact message text and how to fix each — plus the machine-readable quick-fix catalog. |
| Re-entrancy | The runtime guard against resolution cycles compile-time validation cannot see: what it detects, the diagnostic path, the cost, and the opt-out (P1-20). |
| Construction ordering | The deterministic construction, caching, and teardown contract — release order, factory order, and why it is testable (P1-18). |
| Concurrency | The single-threaded-per-container contract, external synchronization, and what changes if the toolchain grows threads (P1-19). |
| Ownership and memory | Who owns which instance, Copyable requirements, destruction, and why disposal is explicit (the opt-in lifecycle hooks). |
Trust, correctness, and release readiness (P0)
| Document | What it covers |
|---|---|
| Release metadata and versioning | The canonical release manifest, the synced locations, the validator, and the version-update workflow (P0-01). |
| Compiler compatibility | The evidence-based platform matrix: verified / ci-verified / experimental / unsupported tiers and what backs them (P0-02). |
| Lifecycle safety diagnostics | The opt-in debug_tracking specialization: tracked caches, close records, and the destructor-time unclosed-resource diagnostics MJDI-D001/D002 (P0-03). |
| Close semantics | The exact, test-pinned behavior of Container.close() and Scope.close_scope() (P0-04). |
| Lifecycle failure policy | What happens when cleanup fails: the non-raising pre_destruct contract, exactly-once cleanup, and the post_construct failure path (P0-05). |
| Validation output contract | The stable diagnostic-ID system: pinned IDs, the ID policy, and the compiler-diagnostic limitations (P0-06). |
| Test inventory | The authoritative suite inventory, the four distinct coverage categories, and the 54/55 reconciliation (P0-07). |
| Runtime error reference | The four runtime error categories with stable IDs, context, and remediation (P0-08). |
| Alias semantics | The complete alias contract: lifetimes-not-instances, cache ownership, precedence, and why chains are impossible (P0-09). |
| Scope behavior matrix | The provider/lifetime/scope matrix with cache ownership — every row test-pinned (P0-10). |
| Release checklist | The release gate, the CI jobs, and the manual pre-tag checklist. |
| Migration notes | Every 0.9.0 change classified: additive / behavior clarification / bug fix / deprecation / breaking. |
| Migration guide: 0.7 → 0.8 | The actual 0.8.0 API delta with before/after examples and verification steps. |
| Migration guide template | The structure every future release's migration guide extends. |
Reference
| Document | What it covers |
|---|---|
| API reference | Every public symbol, organized by area — signatures generated from the source so they cannot drift (P1-12). |
| Documentation website | The website serving this set: versioned URLs, copy-as-markdown, raw endpoints, search, version switcher. |
| Graph export | graph_json / graph_dot: the deterministic, versioned dependency-graph export (P1-01). |
| Graph visualization | The interactive graph viewer in the documentation website (P1-02). |
| Graph diff | Comparing two exports with CI-friendly exit codes (P1-03). |
| Explain resolution | explain_resolution: why a service resolves the way it does (P1-04). |
| Composition roots | The four starter templates and what each demonstrates (P1-05). |
| Testing | The test suite, compile-fail fixtures, golden outputs, the testing patterns, and the static coverage methodology and its 95% gate. |
| Lifecycle tracing | The opt-in, deterministic event log (P1-15). |
| Cache statistics | The opt-in cache-activity counters (P1-16). |
| Performance | The benchmark suite, methodology, recorded results, and the regression policy (P1-17). |
| IDE integration | The diagnostic catalog schema, problem matchers, and the editor integration starter (P1-11). |
| MCP server | The /api/mcp Model Context Protocol endpoint: transport, tools, resources, error model, client configuration. |
| Changelog | Release history. |
Design and internals
| Document | What it covers |
|---|---|
| Architecture | Components, the compile-time/runtime split, the registry chain, dispatch mechanics, design rationale. |
| Technical investigation | The compiler-feature verification matrix (33 verified/unsupported rows plus implementation findings) behind every design decision. |
| Known limitations | What Mojo 1.2.0 cannot express, the workarounds, and every deviation from the product requirements. |
| Release report | The 0.9.0 implementation, test, compatibility, and readiness report (deliverables A-F). |
| Acceptance criteria | The status of every product requirement and functional requirement. |
Suggested reading paths
- New to dependency injection: Core concepts → Getting started → Tutorial → Usage guide.
- Experienced with DI, new to Mojo: Getting started → Core concepts (focus on the value-semantics sections) → Providers → Ownership and memory.
- Building an application now: Tutorial → Patterns and best practices → Diagnostics (keep it open while the compiler talks to you).
- Evaluating mjdi: Core concepts → Known limitations → Acceptance criteria → FAQ.
- Contributing to mjdi: Architecture → Technical investigation → Testing → Compile-time validation.
Where the truth lives
- Behavior is defined by the source in
mjdi/and pinned by the test suite (tests/, driven byscripts/run_tests.sh; the authoritative inventory reports 114/114 suite checks — see../tests/INVENTORY.md— pass on Mojo 1.2.0 — unit, compile-fail, crash-expected, golden examples, templates, and the Python tooling checks). - Coverage claims come from
scripts/coverage_report.py(library API surface: 814/814 declarations, 100%) andscripts/example_coverage.py(example declarations: 166/166, 100%), both gated at 95%. - Compiler claims are backed by
experiments/exp1throughexp10and the compile-fail fixtures intests/compile_fail/. - Suite and coverage counts come from the generated test inventory
(
tests/INVENTORY.md, P0-07); release metadata is validated againstrelease/manifest.json(P0-01). - Performance claims are backed by
benchmarks/with the recorded results inbenchmarks/RESULTS.md(P1-17). - If a document and the code ever disagree, the code and its tests win — please report the doc issue.