bitrix-service-locator
Installation
SKILL.md
ServiceLocator (DI)
Baseline: main 23.0+ · Verified: main 26.800.0
Where constructor DI is allowed (services yes; controllers via action params; commands and handlers no): bitrix-framework. Domain classes never touch the container.
How get($id) resolves (Since main 26.250*)
| Key | Result |
|---|---|
Built before, or addInstance() |
the same instance |
| Not registered, class exists | autowired: each ctor param = get(<its type>); a param with a default gets the default |
| Registered interface / abstract class | className → implementation autowired (constructorParams ignored); constructor closure → called with constructorParams as args |
| Registered concrete class or string id | className → new $class(...array_values(constructorParams)), no autowire; constructor closure → called without args |
- Instances are cached for the process unless the entry has
'singleton' => false. - A cycle throws
CircularDependencyException. An untyped, union or scalar param without a default throwsServiceNotFoundException. - Before 26.250: every registered key is built by
new $class(...constructorParams)orconstructor(). Unregistered classes are autowired only if all ctor params are concrete classes (no interfaces, defaults ignored). Nosingletonoption. On such kernels bind implementations with dependencies through aconstructorclosure.