DEV Community

loading...

A Container/Dependecy Injection for Flutter apps

Pedro Massango
Software Engineer at Monstarlab
・1 min read

In the past few months We made a simple and small Container library to use internally in the company that I'm currentlly working for. It is available in this repository on GitHub. You can try it and leave some feedback. We will keep it up because we are using it for real projects.

Features

  • Create singleton instances;
  • Create factory instances (recreated on every call);
  • Register instances using Module;
  • Get instances from anywhere using the get() function.
  • Logs printed while in DEBUG mode.
  • Easy to test.
  • Doesn't use reflection.

Concepts

  • get() => Used to resolve the instance of a registered class.
  • inject() => Used to resolve a dependency inside a Module.
  • single() => Used to register a singleton instance. You will receive a the same instance every time you use get().
  • factory() => Used to register a factory instance. You will receive a new instance every time you use get().

Read more here and give it a start.

Discussion (0)