Specx diwire composition

From maksimzayats/specx · View interactive version

Specx diwire composition is an AI agent skill from the GitHub repository maksimzayats/specx. Wire dependency injection for a specx Python service with `diwire`. Use when adding `ioc/container.py`, explicit dependency registrations for capabilities, repositories, gateways, UoW managers, clients, settings, or factories, `Injected[...]` constructor fields, FastAPI app factory/lifecycle composi

How to use this skill

Skill file

specx Diwire Composition

Use this skill whenever object graphs, factories, controllers, adapters, or test

overrides need diwire. Read references/diwire.md before writing DI code.

Rules

Injected[DependencyType].

application functions with resolver_context.inject.

abstractions or existing instances that auto-wiring cannot infer.

tests create or use diwire.Container.

to call container.aclose() during app shutdown.

logging is configured once by a top-level infrastructure configurator; classes

that log create local stdlib loggers.

singleton factories. Register a settings instance only for an intentional

test override or an explicitly prebuilt configuration object.

implementations, factories, and instances that auto-wiring cannot infer.

Keep registration in private _register_dependencies(...) inside

ioc/container.py.

FastAPI lifecycle shutdown dependency.

SQLAlchemyReadinessCheckGateway, for ReadinessCheckGateway when

/readyz needs infrastructure checks.

inject the manager and open the active UoW inside execute(...); they do not

inject repositories, active UoWs, providers, SQLAlchemy sessions, engines,

session factories, or concrete infrastructure adapters directly.

project's real get_container(). Put project-wide test overrides in that

fixture and register scenario-specific overrides directly in the test before

resolving the target.

They must use the real internal graph; do not mock internal use cases,

services, or capabilities.

for targets with async methods; use await container.aresolve(...) only when

DI construction itself has async providers.

them. Reused unit-test doubles may live in mirrored

tests/unit/core/<scope>/{capabilities,gateways,repositories}/fake_<source_module>.py

modules.

needs to change.

tests/_support/fakes, tests/**/_fakes.py, or fake modules outside

those mirrored unit port/capability packages.

diwire.integrations.pytest_plugin, and do not use Injected[...]

parameters in test functions.

manager's state-aware manager.app to the HTTPX2 ASGITransport.

Code Style

Use blank lines as logical separators in all code. Keep related statements

together, but separate independent setup, action, assertion, response, branch,

and transformation groups so long blocks stay readable.

References

composition, and test override patterns.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.