ioc 0.1.0 copy "ioc: ^0.1.0" to clipboard
ioc: ^0.1.0 copied to clipboard

discontinued
outdated

A starting point for Dart libraries or applications.

Ioc #

The most simple Ioc Container of Dart and Flutter

Goal #

Keep it minimal

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. 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
}

6
likes
0
pub points
50%
popularity

Publisher

unverified uploader

A starting point for Dart libraries or applications.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on ioc