Skip to content
pubscout

auto_injector

2.2.0, released 5 months ago by flutterando.com.br

Automatic dependency injection system for Dart and Flutter without build_runner.

WASM-ready
$ flutter pub add auto_injector
Source repository

What it does

Allows registering factories, singletons, lazy singletons, and instances without requiring code generation. It automatically analyzes and injects constructor parameters and supports modularization.

AI-written summary of version 2.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want automatic dependency injection without build_runner overhead
  • You are building a modular Flutter or Dart application
  • You need automatic parameter injection for constructors

Skip it when

  • You prefer compile-time dependency injection safety via code generation
  • Your architecture strictly requires a different DI container like get_it or injectable

Strengths

  • No build_runner required
  • Supports modularization and hierarchical injectors
  • Handles automatic parameter injection and bind configuration

Weaknesses

  • Relies on runtime reflection/analysis instead of compile-time code generation
  • Fewer community packages or extensions compared to older established alternatives like get_it

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
2
final autoInjector = AutoInjector();

void main() {
  autoInjector.add(Controller.new);
  autoInjector.addSingleton(Datasource.new);
  autoInjector.commit();

  final controller = autoInjector.get<Controller>();
}

Alternatives

Packages that do the same job and could replace auto_injector.

  • get_it

    If you prefer a manual service locator approach without reflection overhead.

  • injectable

    If you prefer build_runner and compile-time annotations for dependency injection.

Works with

Packages commonly used together with auto_injector: ones it builds on, ones built on it, and its own family.