Skip to content
pubscout

flutter_simple_dependency_injection

2.0.0, released 6 years ago by an unverified publisher

A simple dependency injection and service locator implementation that avoids mirrors.

WASM-ready
$ flutter pub add flutter_simple_dependency_injection
Source repository

What it does

Allows registering types, singletons, and simple values using factory functions. It supports multiple isolated injectors, named types, and passing parameters during instance retrieval without relying on code generation or dart:mirrors.

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

Use it when

  • You want a straightforward dependency injection container without code generation overhead.
  • You need support for multiple isolated injector instances for testing or isolates.

Skip it when

  • You prefer compile-time safe dependency injection via code generation like injectable.
  • You want a fully-featured reactive scope manager.

Strengths

  • No code generation or mirrors required, leading to high performance.
  • Supports multiple named injectors and isolated containers.
  • Allows passing additional parameters when retrieving instances.

Weaknesses

  • Manual mapping of every type and dependency is required.
  • No compile-time safety or verification of dependencies.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0

Add the dependency to pubspec.yaml and import the injector.

import 'package:flutter_simple_dependency_injection/injector.dart';

void main() {
  final injector = Injector();
  injector.map<Logger>((i) => Logger(), isSingleton: true);
  final logger = injector.get<Logger>();
}

Alternatives

Packages that do the same job and could replace flutter_simple_dependency_injection.

  • get_it

    It is widely used, highly mature, and provides a similar lightweight service locator approach.

  • injectable

    It uses code generation to automatically wire up dependencies, saving manual mapping effort.