Getting Started

Learn how to add dependency-injector to your Rust project and start using dependency injection.

Installation

Add dependency-injector to your Cargo.toml:

Optional Features

Enable optional features based on your needs:

  • tracing - Enable tracing integration for debugging (enabled by default)
  • async - Enable async/await support with Tokio

Quick Start

Here's a simple example to get you started:

Core Concepts

Container

The Container is the central piece of dependency-injector. It stores and manages your services. Any type that implements Send + Sync + 'static can be registered.

Service Lifetimes

Dependency Injector supports three service lifetimes:

Singleton

One instance shared everywhere. Created immediately on registration.

Lazy Singleton

One instance shared everywhere. Created on first access.

Transient

New instance created every time you resolve the service.

Next Steps