ioc 0.3.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new48

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
  Ioc().use<MyClass>('MyClass');
}

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);

  Ioc().use<A>('A').someMethod();

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

  Ioc().use<A>('A').someMethod();
}

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')
  Ioc().use<A>('A').someMethod();

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

  Ioc().use<A>('A').someMethod();
}

0.2.1

  • Support singleton in .bind() and global

0.1.0

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

0.0.0

  • Initialize project

example/ioc_example.dart

import 'package:ioc/ioc.dart';

class A {
  void someMethod()
  {

  }
}
class B {}

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

  Ioc().use<A>('A').someMethod();
}

Use this package as a library

1. Depend on it

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


dependencies:
  ioc: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.3.0 Oct 21, 2018 Go to the documentation of ioc 0.3.0 Download ioc 0.3.0 archive
0.2.1 Oct 21, 2018 Go to the documentation of ioc 0.2.1 Download ioc 0.2.1 archive
0.1.1 Oct 21, 2018 Go to the documentation of ioc 0.1.1 Download ioc 0.1.1 archive
0.1.0 Oct 21, 2018 Go to the documentation of ioc 0.1.0 Download ioc 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Format lib/ioc.dart.

Run dartfmt to format lib/ioc.dart.

Maintenance suggestions

The description is too long. (-10 points)

Search engines will display only the first part of the description. Try to keep it under 180 characters.

Dependencies

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