litestar-dependency-injection
Installation
SKILL.md
Dependency Injection
Execution Workflow
- Choose the contract to inject first: settings object, service, repository, session, current user, or request-derived value.
- Pick the narrowest scope that should own it: app, router, controller, or handler.
- Implement the provider as a callable wrapped in
Provide, choosing async, sync, or generator form based on lifecycle needs. - Keep the dependency key identical to the injected parameter name.
- Use overrides intentionally at lower scopes and in tests.
- Mark special cases with
Dependency(...)when validation, defaults, or OpenAPI behavior need to be explicit. - Verify cleanup behavior for generator dependencies and startup-time failure for missing explicit dependencies.