Service container is a source of service instances in the new CRM API.

It also serves as service itself.

Instance of this service (as well as the majority of others) are located in в DI\ServiceLocator.

If desired, you can re-define the container to modify business logic, without updating product kernel.

Method Description Available from version
public static function getInstance(): Container
Method returns container instance.
public static function getIdentifierByClassName
(string $className, array $parameters = null): 
Method returns string identifier for ServiceLocator by class name and additional string parameters.
public function getFactory(int $entityTypeId): 
Method returns a factory instance for the type $entityTypeId, if available.
Not all entity types have factories. If no factory is available, you can pass entityTypeId of non-existing SPA.
public function getDynamicFactoryByType(Type $type): 
Method returns a factory instance of SPA fororm-object.
public function getUserPermissions
(?int $userId = null): UserPermissions
Method returns an access permission service instance for user with $userId.
When $userId is not specified, access permissions will be retrieved from global context.
public function getType(int $id): ?Type
Method returns SPA ORM object by its $id.
Note that column is for ID, not for ENTITY_TYPE_ID
public function getType(int $id): ?Type
Method returns SPA ORM object by its $id.
Note that column is for ID, not for ENTITY_TYPE_ID
public function getTypeByEntityTypeId
(int $entityTypeId): ?Type
Method returns SPA ORM object by its $entityTypeId.
Note, that column is ENTITY_TYPE_ID
public function getLocalization(): Localization
Method returns localization service instance.
public function getRouter(): Router
Method returns routing service instance.
public function getContext(): Context
Method returns global context instance.
public function getOrmObjectConverter(): 
Method returns ORM object converter instance.
public function getItemConverter(): 
Method returns Item converter instance.
public function getStageConverter(): 
Method returns Stage converter instance.
public function getTypeConverter(): 
Method returns SPA converter instance.
public function getUserBroker(): 
Method returns user broker instance.
public function getCompanyBroker(): 
Method returns company broker instance.
public function getContactBroker(): 
Method returns contact broker instance.
public function getDirector(): Director
Method returns scenario service.
public function getDynamicTypeDataClass(): string
Method returns SPA table.
public function getEventHistory(): EventHistory
Method returns History service instance.
public function getTypesMap(): TypesMap
Method returns CRM types map instance.
public function getDynamicTypesMap(): 
Method returns SPA map instance.
public function getRelationManager(): 
Method returns Binding manager instance.
public function getTypePresetBroker(): 
Method returns SPA preset broker.
public function getParentFieldManager(): 
Method returns binding fields manager.
public function getPullManager(): PullManager
Method returns push manager.
public function getFilterFactory(): 
Method returns class factory when handling filter.
public function getAccounting(): Accounting
Method returns total calculation service.
public function getFileUploader(): FileUploader
Method returns file loading service.


use Bitrix\Crm\Service;

$container = Service\Container::getInstance ();
$router = $container->getRouter();
// идентично
// $router = DI\ServiceLocator::getInstance()->get('crm.service.router');
$entityTypeId = \CCrmOwnerType::Deal;
$factory = $container->getFactory($entityTypeId );
if (!$factory)
    echo 'factory not found' ;
© «Bitrix24», 2001-2023