Dependency injection for js/ts projects based on @fozy-labs/simplest-di package.
Ships in fozy-labs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
DI for js/ts projects. Classes decorated with @injectable are managed by the container — resolved via inject(), never instantiated with new.
Two layers:
inject, injectable, Scope, contracts). Works in Node, workers, tests, any framework.setupReactDi, DiScopeProvider, useScope). Requires React ≥ 19.Uses TC39 Stage 3 decorators. Do not enable experimentalDecorators in tsconfig.json.
@injectable — lifetimesimport { injectable } from "@fozy-labs/simplest-di";
@injectable("SINGLETON") // one instance per app (also the default for bare `@injectable()`)
export class SessionStore { ... }
@injectable("SCOPED") // one instance per Scope
export class OrderApi { ... }
@injectable("TRANSIENT") // new instance per inject() call (rare)
export class Logger { ... }
| Lifetime | When to use |
|---|---|
"SINGLETON" | App-wide — SessionStore, ThemeStore, cross-cutting infrastructure. |
"SCOPED" | Tied to a Scope (page/widget subtree) — most stores and all API classes. |
"TRANSIENT" | New instance per inject(). Rare; only when each consumer needs unique state/metadata. |
Detailed form:
@injectable({
lifetime: "SCOPED",
requireProvide: true, // @default true. SCOPED option to disable auto-providing by `inject()`
onScopeInit() {
this.socket.connect(); // instance is `this`, not an argument
return () => this.socket.close(); // runs on scope dispose
},
})
export class FeedStore { ... }
onScopeInit runs on scope init; the returned function runs on scope dispose. Use it — never side-effect code in the constructor.requireProvide: false lets a SCOPED class be auto-created on first inject() in any active scope. Use sparingly.injectinject(Token) // resolve from the current scope
inject(Token, scope) // resolve from an explicit Scope
inject(Token, TAG) // resolve from the nearest ancestor scope carrying TAG
SCOPED legal calls:
@injectable class,scope.runInScope(() => ...) — synchronous only.@injectable("SCOPED")
export class OrderListStore {
private readonly _api = inject(OrderApi);
private readonly _session = inject(SessionStore);
}
inject.provide vs injectinject.provide is just inject with requireProvide forced off — it both registers and returns the instance.
| Error | Cause |
|---|---|
MustBeProvidedError | SCOPED class with requireProvide: true injected without provide. |
NonCompatibleParentError | SINGLETON or TRANSIENT injects a SCOPED — lifetime contract violated. |
CircularDependencyError | A injects B, B injects A inside class-field initializers. |
UnboundContractError | inject(contract) called before contract.bind(Impl). |
ContractAlreadyResolvedError | contract.bind() called after the contract was first resolved. |
Error: No active scope found for scoped injection of X | SCOPED resolved with no current scope and no explicit scope/tag. |
Error: Scope for X does not support initialization callbacks | onScopeInit class resolved in a scope without init$ / destroyed$. |
Full rationale, plus the unidirectional-data-flow rule: references/architecture.md.
onScopeInit.provide — they are available app-wide.new and explicit constructor args.Load these only when the specific situation applies — do not preload.
| Situation | File |
|---|---|
Wiring DI into a React app, setupReactDi, StrictMode, testing components | references/setup-react.md |
Wiring DI outside React — Node, CLI, workers, unit tests, resetRegistry | references/setup-native.md |
DiScopeProvider, useScope, scope keying and tags in a React tree | references/scopes-react.md |
Scope by hand, cascade dispose, runInScope, unstable_createScopesStore | references/scopes-native.md |
inject.define contracts, bind, platform/mock swapping | references/contracts.md |
| Deciding whether DI belongs here at all; store-input data flow | references/architecture.md |
Pick one setup file and one scopes file matching the target environment — loading both the native and React variants of the same topic is redundant.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
4 skills in this plugin
/fozy-labs-fsdFeature-Sliced Design (FSD) v2.1 — deciding which layer, slice and segment a piece of frontend code belongs to, plus the fozy-labs conventions.
/fozy-labs-rx-apiServer-state layer for js/ts projects based on the Query module of @fozy-labs/rx-toolkit (createApi / createResource / createCommand) — caching, SWR, optimistic updates, React hooks.
/fozy-labs-signalsReactive state primitives via @fozy-labs/rx-toolkit — Signal.state / compute / effect, LocalSignal, RxJS interop and the useSignal React hook.
/fozy-labs:fozy-labs-difrom fozy-labs
npx claudepluginhub fozy-labs/astp --plugin fozy-labs