Documentation

ServiceLocator

Service Locator class

Method Description Available from version
\Bitrix\Main\DI\ServiceLocator::getInstance().
Service registration
\Bitrix\Main\DI\ServiceLocator::addInstance(string $code, $service): void
Registration of already created or initialized service. Parameters:
  • $code {string} - Service name. This name is used to query the service.
  • $service {object} - Specific service object.
\Bitrix\Main\DI\ServiceLocator::addInstanceLazy(string $code, $configuration): void
Service registration using configuration for initialization by requirement. Parameters:
  • $code {string} - Service name. This name is used to query the service.
  • $configuration {array} - Description, used by service locator to create a service.
\Bitrix\Main\DI\ServiceLocator::has(string $code): bool
Returns true, when service with $code was registered. Otherwise, false. Parameters:
  • $code {string} - Service name.
\Bitrix\Main\DI\ServiceLocator::get(string $code)
Returns service. When this is a first query, executes service creation. When service with this code is unavailable, throws an exception that implements the interface \Psr\Container\NotFoundExceptionInterface. Parameters:
  • $code {string} - Service name.

© «Bitrix24», 2001-2024
Up