class

Di::Provider::Instance(T)

Inherits Di::Provider::Base < Reference < Object

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.

Constructors

new(factory : -> T, transient : Bool = false)
Source

Instance methods

check_health

Call .healthy? on the cached instance if it responds to it. Returns false if the health probe raises an exception.

Source
instance

Returns the cached singleton instance, or nil if not yet resolved or transient.

Source
key

Registry key used for cycle detection (set on registration).

Source
key=(key : String)

Registry key used for cycle detection (set on registration).

Source
reset!
Source
resolve_typed

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.
Source
shutdown_instance

Call .shutdown on the cached instance if it responds to it.

Source
transient?
Source