litestar-dependency-injection

Coordinate app, router, and handler dependency injection for Litestar applications.

7|1|Updated Mar 2, 2026
One-click install
npx skills add https://github.com/alti3/litestar-skills --skill litestar-dependency-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-dependency-injection
Source: https://github.com/alti3/litestar-skills/tree/main/plugins/litestar/skills/litestar-dependency-injection
Command: npx skills add https://github.com/alti3/litestar-skills --skill litestar-dependency-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamline dependency wiring in Litestar apps, reducing boilerplate and simplifying lifecycle management for services, repositories, and per-request resources.

Core Features & Use Cases

  • Provider-based wiring: Define clear ownership for dependencies and inject them at app, router, or handler scope.
  • Lifecycle-aware wiring: Manage startup/shutdown lifecycles and clean up per-request resources automatically.
  • Test-friendly overrides: Allow easy overrides in tests without mutating global state or internals.

Quick Start

Create a provider for a shared setting and inject it into a route using Provide.

Frequently Asked Questions about litestar-dependency-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage dependency injection scopes in Litestar across app and router levels?

Dependency injection scopes in Litestar are managed by defining clear provider ownership, allowing you to inject dependencies at app, router, or handler levels while enforcing stable provider keys like db_session to avoid global state.

How do I override Litestar dependencies for unit testing without mutating global state?

You can override Litestar dependencies for unit testing by using test-friendly provider overrides, allowing you to inject mock services without mutating global state or touching application internals.

What is the best way to handle service lifecycle and cleanup for per-request resources in Litestar?

The best way to handle service lifecycle in Litestar is using lifecycle-aware wiring, which manages startup and shutdown phases automatically and cleans up per-request resources without boilerplate.

Does Litestar dependency injection support scalable applications with complex service wiring?

Yes, Litestar dependency injection supports scalable applications by streamlining service wiring, coordinating app-wide and router-level dependencies with lifecycle-aware management to reduce boilerplate.

How to set up providers in Litestar to avoid global state and ensure idempotent configuration?

Set up providers in Litestar by using stable keys like settings or current_user, promoting idempotent setup and avoiding global state by defining clear dependency ownership across application scopes.