bitrix-service-locator

Installation
SKILL.md

ServiceLocator (DI) in Bitrix

Bitrix\Main\DI\ServiceLocator is the kernel's PSR-11 container. It should be retrieved via ServiceLocator::getInstance(), but directly in application code only where dependencies cannot be injected the usual way (factories, legacy, static context, console commands, event handlers).

Layer Rules

Context Constructor DI via ServiceLocator? How to get services
Application / Infrastructure services Yes Register in services, autowire constructors
Controller action parameters Yes (autowire) Type-hint service in the action method
Controller constructor No Engine builds controller with Request only — use action params or init() + ServiceLocator::get()
Console commands No CLI does new $commandClass() — call ServiceLocator::get() in execute()
Event handlers No call_user_func_array — resolve inside the handler method
Messenger receivers Yes (must be registered) Handler FQCN must exist in services
  • Domain does not know about the container.
  • Services from Application/ / Infrastructure/ receive dependencies via constructor.
  • Controllers receive services via action parameters only (not constructor).
  • Console commands and event handlers are not created by the container.
Installs
142
GitHub Stars
31
First Seen
Jul 16, 2026
bitrix-service-locator — bxmaximum/bitrix-framework-skills