class
Di::Scope
- Di::Scope
- Reference
- Object
Overview
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).
Defined in:
di/scope.crConstructors
Instance Method Summary
-
#clear : Nil
Clear local providers only (does not affect parent).
-
#count_implementations(interface_type : String) : Int32
Count implementations for an interface type across scope chain.
-
#delete(key : String) : Nil
Remove a provider by key (used for rollback on partial registration failure).
-
#each(& : String, Provider::Base -> )
Iterate over local providers only.
- #fallback_registry : Registry | Nil
-
#get(key : String) : Provider::Base
Get a provider by key, raising ServiceNotFound if not in scope chain.
-
#get?(key : String) : Provider::Base | Nil
Get a provider by key, checking parent scope then fallback registry.
-
#get_all(interface_type : String) : Array(Provider::Base)
Get all providers for an interface type across scope chain.
-
#get_all_keyed(interface_type : String) : Hash(String, Provider::Base)
Get all providers keyed by full key for deduplication in child scopes.
-
#implementation_names(interface_type : String) : Array(String)
Get implementation names for an interface type across scope chain.
-
#local?(key : String) : Bool
Check if a provider is registered locally in this scope only.
- #name : Symbol
-
#order : Array(String)
Return keys in registration order for this scope only.
- #parent : Scope | Nil
-
#register(key : String, provider : Provider::Base) : Nil
Register a provider with the given key.
-
#register_interface(interface_type : String, impl_type : String, provider : Provider::Base) : Nil
Register an interface binding with implementation tracking.
-
#registered?(key : String) : Bool
Check if a provider is registered in this scope, parent, or fallback registry.
-
#reverse_order : Array(String)
Return keys in reverse order for shutdown (this scope only).
-
#size : Int32
Number of local providers.
-
#snapshot : Hash(String, Provider::Base)
Return a snapshot of local providers for iteration without holding mutex.
Constructor Detail
Instance Method Detail
Count implementations for an interface type across scope chain.
Remove a provider by key (used for rollback on partial registration failure).
Iterate over local providers only. Note: Holds mutex for the duration of iteration.
Get a provider by key, raising ServiceNotFound if not in scope chain.
Get a provider by key, checking parent scope then fallback registry.
Get all providers for an interface type across scope chain. Local providers shadow parent/fallback providers with the same impl key.
Get all providers keyed by full key for deduplication in child scopes.
Get implementation names for an interface type across scope chain.
Register a provider with the given key. Raises AlreadyRegistered if the key already exists in this scope.
Register an interface binding with implementation tracking.
Check if a provider is registered in this scope, parent, or fallback registry.
Return a snapshot of local providers for iteration without holding mutex. Use this when callbacks may call back into Di (e.g., health checks).