agentleFS
wachterjohanneswachterjohannes/symfony-skills/skills/services/SKILL.md

services

Skill4 starsChanged 2 months agoMITView on GitHub

Use when creating a service class, wiring dependency injection, or about to edit services.yaml.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Services and dependency injection

The default services.yaml already registers every class in src/ as a service, autowired and autoconfigured. A new class is a service the moment the file exists. The most common mistake is adding configuration for it anyway.

Training data is full of the old style: explicit service ids, arguments: lists, public: true, tags wired by hand. None of that is current. If you are writing a services.yaml entry, name the reason; the legitimate ones are a vendor class outside src/ and a per-environment override. Everything else has an attribute.

What needs no configuration

  • Constructor type-hints resolve themselves. An interface with exactly one implementation autowires like a class.
  • #[AsEventListener], #[AsCommand], #[AsMessageHandler] and friends register the service where it is used. No tag entry anywhere.
  • Services are private and stateless by default. Keep them that way: nothing fetches from the container, everything is injected. ContainerInterface in a constructor is the container pattern the defaults exist to prevent.

When you do configure, do it in the class

public function __construct(
    #[Autowire('%kernel.project_dir%')] private string $projectDir,
    #[AutowireIterator('app.exporter')] private iterable $exporters,
) {
}
  • A scalar comes in via #[Autowire('%parameter%')] or #[Autowire(env: 'NAME')]. Where the value itself belongs is the configuration skill's question.
  • Several implementations of one interface: #[AutowireIterator] or #[AutowireLocator] on the consumer, #[AsTaggedItem] on the implementations.
  • One implementation should win the type-hint: #[AsAlias] on it.

Constructor injection is the default; reach for anything else only with a reason the code can show.

Checking

symfony console debug:autowiring <type> says what a type-hint resolves to, and debug:container <service> shows the final definition. Ask, don't guess; the discover skill lists the rest.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.