litestar-di

Configure non-deprecated dependency injection patterns in Litestar applications.

13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-di
Source: https://github.com/litestar-org/litestar-skills/tree/main/plugins/litestar/skills/litestar-di
Command: npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-di

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Implementing dependency injection in Litestar applications often leads to usage of deprecated patterns, incorrect scope configuration, and messy provider wiring that breaks as the framework evolves. This Skill eliminates these pitfalls by providing clear, up-to-date guidance for all Litestar DI workflows.

Core Features & Use Cases

  • Modern DI Pattern Guidance: Replaces deprecated implicit dependency injection and Dependency() kwargs with current best practices like NamedDependency and NamedDependency[SkipValidation[T]] for Litestar ≥ 2.23.
  • Stack Selection Support: Helps you choose between Litestar's built-in Provide() dependency maps for small to mid-sized apps and Dishka integration for enterprise apps requiring explicit cross-scope resource management.
  • Common Pitfall Prevention: Includes guardrails to avoid mistakes like mixing DI naming conventions, storing database sessions as global mutable state, or hiding business logic inside provider functions.
  • Use Case: A developer building a multi-controller Litestar API can use this Skill to correctly set up request-scoped database sessions and shared service providers without running into deprecation warnings or scope leaks.

Quick Start

Use the litestar-di skill to configure a correct, non-deprecated dependency injection setup for your Litestar application following current best practices.

Frequently Asked Questions about litestar-di

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

FAQPage Schema
How do I set up dependency injection in Litestar without using deprecated patterns?

To set up dependency injection in Litestar without deprecated patterns, apply current best practices like `NamedDependency` and `NamedDependency[SkipValidation[T]]` for Litestar ≥ 2.23 instead of implicit injection or `Dependency()` kwargs.

What is the best way to manage request-scoped database sessions in a Litestar API?

The best way to manage request-scoped database sessions in a Litestar API is by configuring request-scoped providers correctly. This ensures stable provider naming and prevents scope leaks across multi-controller route handlers.

When should I use Dishka integration instead of built-in Provide() dependency maps in Litestar?

You should use Dishka integration instead of built-in `Provide()` dependency maps in Litestar for enterprise applications requiring explicit cross-scope resource management. Use `Provide()` maps for small to mid-sized apps.

Can I hide business logic inside Litestar provider functions?

You cannot hide business logic inside Litestar provider functions. Proper provider setup requires keeping business logic separate to maintain testable provider overrides and strict adherence to Litestar DI best practices.

Why does my Litestar dependency injection setup cause scope leaks and deprecation warnings?

Your Litestar dependency injection setup causes scope leaks and deprecation warnings due to mixing DI naming conventions and storing database sessions as global mutable state. Apply correct provider wiring and modern patterns to resolve these issues.