drupal-service-di

Generate YAML service definitions with constructor injection for Drupal modules.

1|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/AJV009/drupal-devkit --skill drupal-service-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-service-di
Source: https://github.com/AJV009/drupal-devkit/tree/main/plugins/drupal-core/skills/drupal-service-di
Command: npx skills add https://github.com/AJV009/drupal-devkit --skill drupal-service-di

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Drupal projects often grapple with scattered service definitions, inconsistent dependency injection, and hard-to-test code. This Skill provides structured patterns and practical examples to standardize service wiring, interface-driven design, and constructor-based injection.

Core Features & Use Cases

  • Centralized service definitions with YAML wiring examples for Drupal 10/11.
  • Interface-first design and constructor injection practices to improve testability and maintainability.
  • Use Case: Create a ContentManager service and a dependent subscriber with proper DI, then swap implementations via interfaces without touching call sites.

Quick Start

Create a module service that defines an interface, a concrete class, and a Drupal service tag wired via YAML, and inject the interface into a block that renders content.

Frequently Asked Questions about drupal-service-di

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

FAQPage Schema
How do I set up Drupal dependency injection for a custom module service?

To set up Drupal dependency injection, define an interface, implement a concrete class, and wire the service via YAML using constructor injection rather than static calls to ensure modular, testable code.

When do I need YAML service definitions in Drupal module development?

You need YAML service definitions when wiring dependencies for custom modules, enabling centralized service configuration and interface-driven implementation swapping without modifying call sites.

What is the best way to swap Drupal service implementations without touching call sites?

The best way to swap Drupal service implementations is using interface-driven design with constructor injection, allowing you to change underlying classes while keeping dependent code untouched.

Does this dependency injection pattern work with Drupal 10 and 11 module development?

Yes, these dependency injection patterns apply to Drupal 10 and 11 module development, providing structured YAML wiring examples for plugin wiring and service substitution scenarios.

Why should I avoid static calls in Drupal service classes?

Avoid static calls in Drupal service classes because they break testability and maintainability; constructor injection enforces cleaner dependency management and supports interface-driven design.