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

outdated

Inversion of control based on dependency injection through containers.

dioc #

Inversion of control based on dependency injection through containers.

Usage #

A simple usage example:

final container = Container();
container.register<Service>((c) => MockService());
container.register<Service>((c) => Controller(c.create(Service)));

final created = container.create<Controller>();
final singleton = container.singleton<Controller>();

You can also name registrations if multiples instances or factories of the same type are needed.

final container = Container();
container.register<Service>((c) => WebService());
container.register<Service>((c) => MockService(), name : "demo");

final web = container.create<Service>();  // or container<Service>() since Container is callable
final demo = container.create<Service>(factory: "demo");

It is also possible to have multiple named singleton instances :

final container = Container();
container.register<Service>((c) => WebService());
container.register<Service>((c) => MockService(), name : "demo");

final web = container.singleton<Service>();
final demo = container.singleton<Service>(name: "demo", factory: "demo");

If you want to reset your container use the unregister or reset methods.

Code generation #

A dioc_generator package is also available for simplifying injections based on constructor analysis.

Notes #

All dependency resolution isn't based on mirrors because it is intended to be used with strong mode.

Currently, the package is intended to be used with Dart 1, but it will be migrated to Dart 2 very soon to use strong typed generics instead.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

3
likes
0
pub points
10%
popularity

Publisher

unverified uploader

Inversion of control based on dependency injection through containers.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on dioc