ioc 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

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 Nov 8, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:ioc/ioc.dart.

Health suggestions

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

Analysis of lib/ioc.dart reported 1 hint:

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

Maintenance suggestions

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 is getting outdated. (-4.66 points)

The package was last published 54 weeks ago.


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