class
Di::Provider::Instance(T)
- Di::Provider::Instance(T)
- Di::Provider::Base
- Reference
- Object
Overview
Generic provider that stores a typed factory and optional singleton cache.
Singleton (default): the factory runs once on first resolve, result is cached. Transient: the factory runs on every resolve, nothing is cached.
Defined in:
di/provider.crConstructors
Instance Method Summary
-
#check_health : Bool | Nil
Call .healthy? on the cached instance if it responds to it.
-
#instance : T | Nil
Returns the cached singleton instance, or nil if not yet resolved or transient.
-
#key : String
Registry key used for cycle detection (set on registration).
-
#key=(key : String)
Registry key used for cycle detection (set on registration).
- #reset! : Nil
-
#resolve_typed : T
Type-safe resolve with circular dependency guard.
-
#shutdown_instance : Nil
Call .shutdown on the cached instance if it responds to it.
- #transient? : Bool
Instance methods inherited from class Di::Provider::Base
check_health : Bool | Nil
check_health,
key=(key : String)
key=,
reset! : Nil
reset!,
shutdown_instance : Nil
shutdown_instance,
transient? : Bool
transient?
Constructor Detail
Instance Method Detail
Call .healthy? on the cached instance if it responds to it. Returns false if the health probe raises an exception.
Returns the cached singleton instance, or nil if not yet resolved or transient.
Type-safe resolve with circular dependency guard.
The fast-path reads @instance without holding @mutex. This is safe because:
- @instance transitions nil → T exactly once under @mutex in resolve_singleton.
- A stale nil read just falls through to the mutex-protected path.
- @instance is only set to nil again via reset!, which requires no active scopes.