Skip to content
/ injector Public

A simple, easy and flexible dependency injection library, based on Dart

License

Notifications You must be signed in to change notification settings

games/injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Injector

This is a simple, easy and flexible dependency injection library, based on Dart. I use it for my projects. Inspired by swiftsuspenders.

Usage

  var injector = new Injector();
  
  // mappings
  
  // create a basic mapping, will instantiate a new Cat for each request.
  injector.map(Cat);
  // map to a value, as singleton
  injector.map(Cat).toValue(cat);
  // map to a value with name
  injector.map(Cat, "cat").toValue(cat2);
  // map as singleton
  injector.map(Dog).asSingleton();
  // map as singleton to another class
  injector.map(Cat, "cat2").toSingleton(Dog);
  
  // get
  var c = injector.get(Cat);
  var c2 = injector.get(Cat, "cat");
  
  //injection using metadata
  class InjectTarget {
    @Inject("cat")
    Cat cat;
    @inject
    Dog dog;
  }
  var t = new InjectTarget();
  injector.inject(t);
  
  

About Me

About

A simple, easy and flexible dependency injection library, based on Dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages