xp-forge / inject

Dependency injection for the XP Framework
0 stars 0 forks source link

Make it possible to pass instances to `singleton()` #31

Closed thekid closed 1 year ago

thekid commented 1 year ago

Extends https://github.com/xp-forge/inject/pull/23 and adds the possibility to pass instances to the singleton() method.

$injector= new Injector(Bindings::using()
  ->singleton(Signing::class)                        // Binds a single Signing instance to Singing
  ->singleton(Algorithm::class, SHA256::class)       // Binds a single SHA256 instance to Algorithm
  ->singleton(Storage::class, new InFileSystem('.')) // 🆕 Always returns the instance passed
);

While the upper two provide lazily instantiated singletons, this new functionality offers an eager version.

thekid commented 1 year ago

Released in https://github.com/xp-forge/inject/releases/tag/v5.5.0