plugins/litestar/skills/litestar-dependency-injection/SKILL.md
Apply Litestar dependency injection with Provide, Dependency markers, layered scopes, overrides, generator-based cleanup, per-request caching, and nested providers. Use when wiring services, settings, database sessions, request-derived resources, or test doubles into Litestar handlers, controllers, routers, and apps. Do not use when plain local function parameters or a small helper are sufficient.
npx skillsauth add alti3/litestar-skills litestar-dependency-injectionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Provide, choosing async, sync, or generator form based on lifecycle needs.Dependency(...) when validation, defaults, or OpenAPI behavior need to be explicit.settings, db_session, current_user, tenant, clock.TYPE_CHECKING unless you also provide a working runtime signature namespace.self in providers, never positional-only runtime arguments.Litestar resolves dependencies from outer to inner scope, with lower scopes overriding higher ones when the same key is reused.
Choose the lowest scope that still matches the reuse boundary. Reusing the same key is an intentional override contract, not a naming accident.
sync_to_thread=True for blocking I/O or CPU-heavy sync providers.sync_to_thread=False for cheap, non-blocking sync providers to document intent and avoid warnings.Read only the sections you need:
yield cleanup, overrides, caching, nested dependency graphs, and service wiring patterns, read references/provider-patterns.md.Annotated[..., Dependency(...)] usage, validation control, OpenAPI-safe defaults, and fail-fast explicit dependency markers, read references/dependency-markers.md.dep1.sync_to_thread=True.skip_validation=True broadly instead of fixing the type boundary.sync_to_thread behavior.Dependency(default=...) is used when fallback dependencies must stay out of OpenAPI.Dependency() markers catch missing required wiring at startup.litestar-databases for SQLAlchemy or Piccolo session provisioning.litestar-testing for dependency override patterns and client-based verification.litestar-security or litestar-authentication when DI is carrying auth context.litestar-routing when the main issue is route/controller structure rather than service wiring.development
Build Litestar WebSocket endpoints with low-level websocket handlers, websocket listeners, websocket streams, dependency injection, custom websocket classes, transport-mode control, and graceful connection lifecycle handling. Use when implementing bidirectional real-time communication, reactive websocket message handling, or proactive server push over WebSockets. Do not use for server-side pub/sub fanout that is better expressed with channels alone.
tools
Test Litestar applications with TestClient, AsyncTestClient, create_test_client, websocket test helpers, dependency overrides, mocked dependencies, lifecycle-aware fixtures, and deterministic success and failure assertions. Use when adding or fixing Litestar test coverage, including exception contracts, override precedence, websocket behavior, event-bus side effects, or live-server-only response patterns. Do not use as a substitute for production observability or runtime debugging strategy.
development
Configure Litestar templating with `TemplateConfig`, Jinja/Mako/MiniJinja engines, file-or-string `Template` responses, request and CSRF-aware context, template callables, and custom engine integration. Use when implementing or fixing server-rendered HTML in Litestar. Do not use for static asset serving or pure JSON API endpoints.
development
Configure Litestar stores and the store registry for caching, server-side sessions, rate limiting, and other key-value state with explicit backend selection, bytes-safe data handling, TTL and renewal policy, namespacing, registry wiring, and lifecycle cleanup. Use when a Litestar app depends on `MemoryStore`, `FileStore`, `RedisStore`, `ValkeyStore`, or `StoreRegistry`. Do not use for relational persistence, domain repositories, or response-caching policy details that belong in database or caching-focused skills.