class

Di::Scope

Inherits Di::KeyParser < Reference < Object

A scope provides isolated provider registration with parent inheritance. Child scopes shadow parent providers without modifying them. Thread-safe for multi-threaded Crystal (-Dpreview_mt).

Constructors

new(name : Symbol, parent : Scope | Nil = nil, fallback_registry : Registry | Nil = nil)
Source

Instance methods

clear

Clear local providers only (does not affect parent).

Source
count_implementations(interface_type : String) : Int32

Count implementations for an interface type across scope chain.

Source
delete(key : String) : Nil

Remove a provider by key (used for rollback on partial registration failure).

Source
each

Iterate over local providers only.

Source
fallback_registry
Source
find_all_by_name(interface_type : String, name : String) : Array(Provider::Base)

Find all named interface providers matching ~Type:Impl:name across scope chain. Child shadows parent by ALIAS NAME, not by full key.

Source
find_all_by_name_keyed(interface_type : String, name : String) : Hash(String, Provider::Base)

Find all named interface providers keyed for deduplication in child scopes.

Source
find_by_name(interface_type : String, name : String) : Provider::Base

Find a named interface provider, raising on ambiguity or not found.

Source
get(key : String) : Provider::Base

Get a provider by key, raising ServiceNotFound if not in scope chain.

Source
get?(key : String) : Provider::Base | Nil

Get a provider by key, checking parent scope then fallback registry.

Source
get_all(interface_type : String) : Array(Provider::Base)

Get all providers for an interface type across scope chain. Child shadows parent by IMPL KEY (Type:Impl segment).

Source
get_all_keyed(interface_type : String) : Hash(String, Provider::Base)

Get all providers keyed by full key for deduplication in child scopes.

Source
implementation_names(interface_type : String) : Array(String)

Get implementation names for an interface type across scope chain.

Source
local?(key : String) : Bool

Check if a provider is registered locally in this scope only.

Source
name
Source
order

Return keys in registration order for this scope only.

Source
parent
Source
register(key : String, provider : Provider::Base) : Nil

Register a provider with the given key. Raises AlreadyRegistered if the key already exists in this scope.

Source
registered?(key : String) : Bool

Check if a provider is registered in this scope, parent, or fallback registry.

Source
reverse_order

Return keys in reverse order for shutdown (this scope only).

Source
size

Number of local providers.

Source
snapshot

Return a snapshot of local providers for iteration without holding mutex.

Source