Skip to content

scope documentation

scope is a small JVM library that treats scopes as first-class runtime objects. A scope is a lexical block you can build, nest, shadow and dispose while the program runs — and a thin dependency injection layer wires objects together by walking the scope graph.

If you have five minutes, read Mental model first: every other page builds on it.

java
import be.theking90000.scope.Scope;

record RootScope() {}
record Config(String value) {}
record Service(Config config) {}

Scope<RootScope> root = new Scope<>(new RootScope());
root.seed(Config.class, new Config("prod"));

Service service = root.get(Service.class); // built and cached as a scope singleton

Table of contents

PageWhat it covers
Mental modelScopes as language blocks, the lifetime model, the visibility/ownership asymmetry.
Getting startedFirst example, step by step, and how get() resolves.
InjectionConstructor injection rules, supported parameter shapes, lazy Provider<T>, cycles.
Qualifiers & collectionsKey<T>, @Named, and injecting all providers of a type.
Scopes & lifecycleParents, shadowing, ownership vs visibility, close(), @PostConstruct / @PreDestroy / AutoCloseable.
Multi-parent scopesDAG scopes, ambiguity, NEAREST vs DEEP resolution.
Extension hooksOnCreatedHook, BeanCreated, Disposer, hook shadowing, batch initialization.
API referenceEvery public member of Scope, Key, Provider, MultiProvider.
ExceptionsThe DiException hierarchy and when each is thrown.
RecipesCommon patterns and a best-practices checklist.

Installation

See the main README for Gradle / Maven coordinates. The library targets Java 21. The base package is:

java
package be.theking90000.scope;

JavaDoc

Every public type and method ships with thorough JavaDoc — it is the most precise reference for exact signatures, edge cases and behavior. Browse it online:

https://theking90000.github.io/scope/javadoc/

(Published from the javadoc jar produced by the build; if the hosted site is not up yet, the same JavaDoc is attached to every release on GitHub Packages.)

Other references

  • Main README — the project landing page (pitch and comparison).
  • scope/README.md — the original, in-depth French reference for the same module.