injector
4.0.0, released 2 years ago by an unverified publisher
A simple to use and lightweight dependency injection library for Dart.
WASM-ready
What it does
It stores instances and builders in a Map internally to act as a dependency injection container. You can register dependencies, singletons, or custom factories and retrieve them later using generic types.
AI-written summary of version 4.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a lightweight dependency injection setup without code generation
- You want to register services and look them up anywhere
Skip it when
- You need a complex dependency injection framework like Dagger
Strengths
- Simple and lightweight
- Supports both dependencies (new instance each time) and singletons
- Lazy loading of instances by default
Weaknesses
- Requires absolute imports for dependencies to avoid issues
- Does not handle complex dependency graphs automatically without manual wiring
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
injector.registerSingleton<Car>(() {
var engine = injector.get<Engine>();
var fuel = injector.get<Fuel>();
var driver = injector.get<Driver>();
return CarImpl(engine, fuel, driver);
});Alternatives
Packages that do the same job and could replace injector.
- get_it
A widely used service locator for Dart and Flutter with similar imperative registration.
89Compare - injectable
Provides annotation-based code generation for dependency injection.
78Compare
Works with
Packages commonly used together with injector: ones it builds on, ones built on it, and its own family.