organic_injector 0.0.4
organic_injector: ^0.0.4

Dart 2 incompatible

Simple dependecy injector for dart and flutter. Inspired by SwiftSuspenders and robotlegs_di.

organic_injection #

dependency injector for flutter that works out of the box without mirrors. Used as a base to do this simple no mirrors implementation.

Getting Started #

Use Injector.instance singleton to access the injector, or wrap it inside your own singleton.

map type to a already instantiated value.

  injector.mapToValue(CounterModel, new CounterModel());

Optionally add name.

  injector.mapToValue(ChangeNotifier,new ChangeNotifier(), name: 'counter_changed');

One advice can be to wrap basic types to distinct classes to avoid confusion.

Injector will return instance that was previously mapped

CounterModel counterModel = injector.getInstance(CounterModel) as Counter;

ChangeNotifier changeNotifier = injector.getInstance(ChangeNotifier,'counter_changed') as ChangeNotifier;

map to a provider

class SecureRandomProvider implements IProvider{

  final Random secure =;
  void destroy() {

  apply({Type type}) => SecureRandom(secure.nextDouble());

class SecureRandom {
  final double random;
  const SecureRandom(this.random);

injector.mapToProvider(SecureRandom,new SecureRandomProvider());

later when you inject into SecureRandom, you will always get unique crypto secure double.

double SecureRandom secureRandom = injector.getInstance(SecureRandom) as SecureRandom;

If you want to provide dependecies of previously mapped values to your mapping, implement IInjectable into the class. Injector will then auto populate mappings

Implement IInjectable to provide chain injection.

class CounterModel implements IInjectable {
void inject(IInjector injector){
    //get your mappings here

get it on pub pub.

and check example project github.

great thanks to robotlegs 2 team for actionscript and for starting this implementation in dart.

pub points

Simple dependecy injector for dart and flutter. Inspired by SwiftSuspenders and robotlegs_di.

Repository (GitHub)
View/report issues



Packages that depend on organic_injector