dependency-injection
Skill4 starsChanged 4 months agoMITView on GitHub
Wire a PSR-11 container into a Slim app — register service definitions, resolve invokable controllers from the container, and inject dependencies instead of using globals. Use when the user needs to register service definitions in the Slim container so classes get their dependencies; the user wants Slim to resolve an invokable controller class from the container instead of a closure; the user wants to configure a PSR-11 container for a Slim app via AppFactory::setContainer. Keywords: slim, dependency-injection, psr11, container, definitions, php74.
14 other projects use a version of this.
Adopted by
Most recently taken up by
- codewithmukesh/dotnet-claude-kittheir own version, first seen Nov 8, 2026
- jars-demo/jars-skillstheir own version, first seen Nov 1, 2026
- jame581/GodotPromptertheir own version, first seen Oct 21, 2026
- wrinfotel/verified-android-skillstheir own version, first seen Oct 20, 2026
- andr-ca/agentharnesstheir own version, first seen Oct 15, 2026
- Resgrid/Coretheir own version, first seen Oct 8, 2026
Used with
Projects with it also use api-versioning, caching and 6 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
wpankSkillapi-versioning
API versioning strategies — URL path, header, query param, content negotiation — with breaking change classification, deprecation timelines, migration patterns, and multi-version support. Use when evolving APIs, planning breaking changes, or managing version lifecycles.
Also in 3 projects that use this
wpankSkillcaching
Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.
Also in 3 projects that use this
diego-tobalinaSkilllogging
Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.
Also in 4 projects that use this
Model Context ProtocolSkillproject-structure
Where things live in the Inspector repo — which client owns which surface, what is in core/ versus clients/web, and what each top-level directory is for. Use when locating code, deciding where a new module belongs, or answering which package owns or contains a given area of the codebase.
Also in 3 projects that use this
harrissohail6Skillclean-architecture
Clean architecture and SOLID principles. Auto-activates when designing systems or refactoring code structure.
Also in 3 projects that use this
JohnJBorenSkillci-cd
CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies
Also in 3 projects that use this
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 14
- trezor/trezor-suite★ 1.1ksame name
- jame581/GodotPrompter★ 870same name
- codewithmukesh/dotnet-claude-kit★ 808same name
- GoBetterAuth/go-better-auth★ 277same name
- Resgrid/Core★ 238same name
- garrettw/php-arch-skills★ 13same name
- HamzaSheikh768/Agents-Skills-Lap★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- andr-ca/agentharness★ 1same name
4 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 64
Do not reach for this skill to pull services out of the container inside handlers on demand.
- Distinctive: line 65
Do not introduce a container for a trivial Slim app with a couple of routes and no shared services.
- Very specific: line 73
Create a PSR-11 container (e.g.
- Distinctive: line 74
Add definitions binding interfaces to implementations and factory closures for configured services.
- Distinctive: line 106
Not applicable — no I/O, auth, or untrusted input.
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/slim/dependency-injection/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Slim Dependency Injection
When to use
- The user needs to register service definitions in the Slim container so classes get their dependencies.
- The user wants Slim to resolve an invokable controller class from the container instead of a closure.
- The user wants to configure a PSR-11 container for a Slim app via AppFactory::setContainer.
When NOT to use
- Do not reach for this skill to pull services out of the container inside handlers on demand; that is a service-locator anti-pattern, not injection.
- Do not introduce a container for a trivial Slim app with a couple of routes and no shared services.
Core guidance
- Set the container before creating the app — Build the PSR-11 container, pass it with
AppFactory::setContainer($container)beforeAppFactory::create(), so Slim uses it to resolve handlers.
Quick recipe
- Create a PSR-11 container (e.g. PHP-DI), add definitions, and call
AppFactory::setContainer($container)beforeAppFactory::create(). (verify: The app boots and resolves class-name handlers.) - Add definitions binding interfaces to implementations and factory closures for configured services. (verify: Requesting an interface from the container returns the bound implementation.)
- Register the route with
Controller::classand declare its dependencies as constructor parameters. (verify: The controller runs with its dependencies injected.)
Best practices
- Let the container autowire classes whose dependencies are other typed classes, and write a factory definition (closure receiving the container) only when a service needs configuration or a chosen implementation
- Declare each dependency as a constructor parameter and let the container supply it, rather than storing the container and calling
$c->get(...)inside methods - Register a definition mapping each interface to a concrete class so controllers can type-hint the interface and receive the bound implementation
- Register routes with a
Controller::class(invokable, or[Controller::class, 'method']) so the container instantiates the controller with its dependencies
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Injecting the container into a controller | Depending on the container hides real dependencies and turns the class into an untestable service locator. | Inject the specific services the controller needs as constructor parameters. |
| Constructing dependencies with new inside handlers | Hard-coding construction couples the handler to concrete classes and their own dependencies, defeating the container. | Register the service in the container and inject it so construction stays in one place. |
| Reaching for global singletons instead of the container | Global access bypasses the container, hides dependencies, and makes handlers impossible to test in isolation. | Register the service in the container and inject it into the handler or controller. |
See references/anti-patterns.md.
Common mistakes
- Container ignored because it was set too late — Class-name route handlers fail to resolve because the container was set after
AppFactory::create(). Fix: CallAppFactory::setContainer($container)beforeAppFactory::create(). - NotFoundException for an unregistered service — Resolving an interface or non-autowirable service throws a container NotFoundExceptionInterface. Fix: Add a definition mapping the interface or service id to a concrete factory or class.
- Shared service accumulates request-specific state — A container service is shared (built once), so storing per-request state on it leaks across requests in long-running servers. Fix: Keep shared services stateless; pass per-request data as method arguments or request attributes.
Version notes
- Slim 4 requires an external PSR-11 container (PHP >=7.4) — Slim 4 ships without a built-in container and expects any PSR-11 container (PHP-DI, League Container) via AppFactory::setContainer; Slim 3 bundled Pimple with a different API.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/slim/dependency-injection.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: slim/routing
<!-- graph-fragment: graph/fragments/slim/dependency-injection.yaml -->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
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.

