injectorio 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

InjectorIO - Dependency Injection for Flutter #

Pub support

Inject your dependencies easily and quickly. Register in one place and use get() everywhere to retrieve your instances and InjectorIO will take care of the rest.

Features #

  • [x] Create singleton instances;
  • [X] Create factory instances (recreated on every call);
  • [x] Register instances using Module;
  • [x] Get instances from anywhere using the get() function.
  • [x] Logs printed while in DEBUG mode.
  • [x] Easy to test.
  • [x] Doesn't use reflection.
  • [x] InjectorIO prevents you from keeping instances of classes that extends Widget.

Core concepts #

  • get() => Used to resolve the instance of a registered class. This is what you will use most.
  • 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().

NOTE: don't get confused with get() and inject(). Just remember this: If you are inside a Module and you want to resolve a dependency use inject(), but if you are not within a Module always use get().

Usage #

Basic Sample #

Here is how you can easily use this package. Import this package and register your dependency instance, then in any part of your code use get() to resolve the registered instance.

import 'package:injectorio/injectorio.dart';

void main(){
  .single( CountriesRepository()); // register a instance


class _MyHomePageState extends State<MyHomePage> {
  // This works
  // final CountriesRepository repository = get();

  CountriesRepository _repository;

  void initState() {
    _repository = get(); // resolve the dependency

  Widget build(BuildContext context) {
    return Container();

Register Dependencies #

import 'package:injectorio/injectorio.dart';

void main() {
  .factory(() => CountriesRepository(get()));


Register Dependencies using Module #

import 'package:injectorio/injectorio.dart';

class CountriesWebService{}

class CountriesRepository{
  final CountriesWebService webService;

class AppModule extends Module{
  AppModule() {
    single( CountriesWebService()); // register a singleton of CountriesWebService
    factory(CountriesRepository(inject())); // the library will take care of getting the instance of CountriesWebService

void main(){


Enable/Disable Logs #

InjectorIO can also provide printed logs while in development mode. The function InjectorIO.start() receives a InjectorMode that can be:

  • [X] DEBUG - Displays logs
  • [X] PRODUCTION - Disables logs. You will not see logs from this package in the console.

The default value for this is DEBUG. If you don't want to see logs, just use production mode:

InjectorIO.start(mode: InjectorMode.PRODUCTION)
.module( AppModule());

Help this Library #

You can help/support by:

  • [X] Reporting a Bug;
  • [X] Making pull request;
  • [X] Write a tutorial about this;
  • [X] ❤️ Staring this repository;

[1.0.4] - 16/09/2019

  • Fixed logging issue: disabled logging in production mode

[1.0.3] - 20/09/2019

  • Removed the required instance definition for factory instances inside a Module

[1.0.2] - 29/08/2019

  • Added logs for debugging purposes and replaced print messages

[1.0.1] - 20/05/2019

  • code formatted

[1.0.0] - 19/05/2019

  • Stable version

[0.1.0] - 19/05/2019

  • Docs updated

[0.0.5] - 15/05/2019

  • Breaking change on the library design

[0.0.4] - 12/05/2019

  • Added Module support

[0.0.3] - 12/05/2019

  • Improved instance query

[0.0.2] - 10/05/2019

  • Added single instances support

[0.0.1] - 10/05/2019

  • First version.


example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  injectorio: ^1.0.4

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:injectorio/injectorio.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/src/bean_registry.dart.

Run flutter format to format lib/src/bean_registry.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (logger).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
logger ^0.7.0+2 0.7.0+2 0.8.3
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies