bitrix-service-locator

Resolve Bitrix services via PSR-11 ServiceLocator with has() and get().

33|3|Updated Jun 5, 2025
One-click install
npx skills add https://github.com/bxmaximum/bitrix_ai_challenge --skill bitrix-service-locator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bitrix-service-locator
Source: https://github.com/bxmaximum/bitrix_ai_challenge/tree/main/.agents/skills/bitrix-service-locator
Command: npx skills add https://github.com/bxmaximum/bitrix_ai_challenge --skill bitrix-service-locator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bitrix applications often suffer from tight coupling and hard-to-test code. ServiceLocator (PSR-11) offers a centralized, testable way to register and resolve services, enabling constructor injection and decoupled controllers.

Core Features & Use Cases

  • Registration of services in .settings.php under the services section.
  • Autowiring and resolving dependencies via has()/get() in controllers, services, and console commands.
  • Binding interfaces to implementations to support swapping components and easier testing.
  • Use Case: Refactor legacy controllers to depend on interfaces instead of concrete classes for maintainability.

Quick Start

Register your services in the module's .settings.php under the services key, then inject dependencies via constructor or controller action parameters.

Frequently Asked Questions about bitrix-service-locator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement dependency injection in Bitrix controllers?

Implement dependency injection in Bitrix controllers by using a PSR-11 ServiceLocator. It resolves dependencies via has()/get() methods at runtime, enabling constructor injection and decoupled application architecture.

What is the best way to decouple Bitrix module services from concrete classes?

The best way to decouple Bitrix module services is binding interfaces to implementations. A ServiceLocator resolves interface dependencies at runtime, supporting component swapping and easier testing.

How do I register services for a Bitrix ServiceLocator?

Register services for a Bitrix ServiceLocator explicitly in the module's .settings.php file under the 'services' section. This configuration enables autowiring and runtime dependency resolution.

Can I use autowiring with console commands in Bitrix?

Yes, you can use autowiring with Bitrix console commands. The ServiceLocator supports resolving dependencies and constructor injection across controllers, module services, and console commands.

Why does my Bitrix application suffer from tight coupling and hard-to-test code?

Bitrix applications suffer from tight coupling when controllers depend on concrete classes. A PSR-11 ServiceLocator centralizes service registration and resolution, enabling testable dependency injection.

Does Bitrix support PSR-11 ServiceLocator for dependency management?

Yes, Bitrix supports PSR-11 ServiceLocator for dependency management. It provides a centralized, testable way to register and resolve services using has()/get() methods across application layers.