Skip to main content

Dependency Injection

Tasteful uses the powerful dependency-injector library to manage component relationships, lifecycles, and testing. This system is the foundation that makes Tasteful’s modular architecture possible and maintainable.
Tasteful leverages the dependency-injector library for its IoC container implementation. For complete API reference and advanced features, visit the official dependency-injector documentation.

Why Dependency Injection?

Dependency injection solves several critical problems in application architecture:

🔧 Testability

Without DI, testing becomes a nightmare of tight coupling:
With DI, testing becomes elegant:

🏗️ Modularity

DI enables true modularity where components can be swapped without code changes:

🔄 Lifecycle Management

Automatically handles singleton patterns, lazy loading, and resource cleanup.

How Tasteful’s DI Works

Tasteful uses declarative containers from the dependency-injector library. Here’s the architecture:

Container Hierarchy

Automatic Service Registration

When you define a flavor, Tasteful automatically registers your services using constructor-based dependency injection:
Behind the scenes, Tasteful:
  1. Analyzes constructor signatures to understand dependencies
  2. Uses graph-based resolution to determine dependency order
  3. Registers providers in the container automatically
  4. Injects dependencies into constructors
  5. Manages lifecycles (singletons, factories, etc.)