Skip to main content
Version: 0.1.1

Interface: DIAdapter

Imported from @react-logic/di

The shape every DI adapter must implement. The framework uses this and never reaches into adapter internals — this is what swaps in/out when you choose between the built-in DI, Angular's, or any other.

Scope is the adapter-private handle representing one DI scope (a node in the parent/child injector tree). The framework treats it as opaque.

Type Parameters​

Scope​

Scope = unknown

The adapter's internal scope handle type. Default is unknown because consumers (the framework) never inspect it.

Properties​

rootScope​

readonly rootScope: Scope

The implicit top-of-tree scope — used when no <Injector> wraps a tree.

Methods​

construct()​

construct<T>(scope, fn): object

Run a constructor (e.g. a logic class) inside scope with full tracking:

  • inject() calls resolve through scope (and ancestors).
  • onDestroy() calls inside fn are captured into the returned dispose. Service-internal onDestroy calls go to the service's own scope — they are not in this dispose.
  • Records every value returned by inject() during fn for the caller (used by useLogic to subscribe to injected services' signals).

Type Parameters​

T​

T

The type returned by fn (typically the constructed instance).

Parameters​

scope​

Scope

fn​

() => T

Returns​

object

dispose​

dispose: () => void

Returns​

void

injected​

injected: unknown[]

result​

result: T


createScope()​

createScope(providers, parent): Scope

Create a child scope of parent that adds providers.

Parameters​

providers​

Provider[]

parent​

Scope

Returns​

Scope


disposeScope()​

disposeScope(scope): void

Tear down a scope: dispose every service it constructed locally and run their onDestroy callbacks. Parent scopes are untouched.

Parameters​

scope​

Scope

Returns​

void


inject()​

inject<T>(token, optional?): T | null

Resolve a token through the currently-active scope (set by runIn/construct).

Type Parameters​

T​

T

The type the token resolves to.

Parameters​

token​

InjectionType<T>

optional?​

boolean

Returns​

T | null


onDestroy()​

onDestroy(fn): void

Register a teardown for the currently-constructing entity.

Parameters​

fn​

() => void

Returns​

void


runIn()​

runIn<T>(scope, fn): T

Run fn with scope as the active injection context — inject() calls inside fn resolve through this scope. Used by useInjector and for one-off resolutions.

Type Parameters​

T​

T

The return type of fn.

Parameters​

scope​

Scope

fn​

() => T

Returns​

T