ioc 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

IoC #

The most simple IoC Container of Dart and Flutter

If you looking for a package that is light-weight and provide production-ready of inversion of control, then this package is right for you.

This package provides only 2 main api, easy to learn and use, but definitely fits most use case in your flutter project.

If you are a server developer developing small or medium scale project, it's very likely you want to use this package. However, large scale project may need more powerful heavy-weight IoC library.

You can use it in your angular project, but we highly recommend you use dependency injection system provided by angular.

Goal #

Keep it minimal, light-weight

Important #

  1. The container does not rely on reflection, it's just a Map, so supports Flutter
  2. Dart2 is required to use this package

Feature #

  1. Supports singleton
  2. Supports binding to anything
  3. Supports lazy initialization (Developing)
  4. Detects circular dependencies (Developing)

Usage #

bind to a string:

import 'package:ioc/ioc.dart';

main() {
  Ioc().bind('MyClass', (ioc) => new MyClass());
  // later
  Ioc().use('MyClass'); // you will get an instance of MyClass
  // with generic if you want

bind to self:

import 'package:ioc/ioc.dart';

main() {
  Ioc().bind(MyClass, (ioc) => new MyClass());
  // later
  Ioc().use(MyClass); // you will get an instance of MyClass

bind to other:

import 'package:ioc/ioc.dart';

main() {
  Ioc().bind(MyClass, (ioc) => new OtherClass());
  // later
  Ioc().use(MyClass); // you will get an instance of OtherClass

bind with other dependency

import 'package:ioc/ioc.dart';

main() {
  Ioc().bind('MyClass', (Ioc ioc) {
    OtherClass other = ioc.use<OtherClass>('OtherClass');
    return new MyClass(other);
  // later
  Ioc().use<MyClass>('MyClass'); // you will get an instance of OtherClass

using singleton:

import 'package:ioc/ioc.dart';

class A {
  void someMethod() {}

main() {
  // use singleton on one
  Ioc().bind('A', (ioc) => new A(), singleton: true);


  // use singleton on all
  Ioc().config['singlton'] = true;


using lazy-loading singleton:

import 'package:ioc/ioc.dart';

class A {
  void someMethod() {}

main() {
  // use lazy loaded singleton on one
  Ioc().bind('A', (ioc) => new A(), singleton: true, lazy: true);

  // class A will only be instantiated after first .use('A')

  // use lazy loaded singleton on all
  Ioc().config['lazy'] = true;


0.2.1 #

  • Support singleton in .bind() and global

0.1.0 #

  • Basic usage of .use() .bind()

0.0.0 #

  • Initialize project


import 'package:ioc/ioc.dart';

class A {
  void someMethod()

class B {}

main() {
  Ioc().bind('A', (ioc) => new A());


Use this package as a library

1. Depend on it

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

  ioc: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or 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:ioc/ioc.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 Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/ioc.dart. (-2.96 points)

Analysis of lib/ioc.dart reported 6 hints, including:

line 3 col 1: Prefer using /// for doc comments.

line 13 col 21: Unnecessary new keyword.

line 15 col 23: Unnecessary new keyword.

line 17 col 33: Unnecessary new keyword.

line 24 col 19: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-46.30 points)

The package was last published 76 weeks ago.

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0