dart_inversion_of_control

Creator: coderz1093

Last updated:

0 purchases

dart_inversion_of_control Image
dart_inversion_of_control Images

Languages

Categories

Add to Cart

Description:

dart inversion of control

Dartioc #
A simple library to facilitate inversion of control in dart. Supports registering multiple
container instances that hold bindings to dependencies. Bindings can be declared as singletons.
You can find the package at: https://pub.dev/packages/dart_inversion_of_control
Installing #
Add this to your package's pubspec.yaml file:
dependencies:
dart_inversion_of_control: ^1.0.0
copied to clipboard
You can install packages from the command line:
dart pub get
copied to clipboard
Usage #
A simple usage example:
void main() {
Container('user').register(User, () => User());

var user = Container('user').locate(User);
print(user.name); // Generic

Container('user').register(User, () => Bob());

user = Container('user').locate(User);
print(user.name); // Bob

Container('user').register(User, () => Alice());

user = Container('user').locate(User);
print(user.name); // Alice

// register a singleton
Container('user').register(User, () => Alice(), singleton: true);
Container('user').locate(User).printName(); // Alice

// register a singleton
Container('user').register(User, () => Bob(), singleton: true);
Container('user').locate(User).printAge(); // 20
}

class User {
String name = 'Generic';
}

class Bob extends User {
@override
String name = 'Bob';

void printAge() {
print('20');
}
}

class Alice extends User {
@override
String name = 'Alice';

void printName() {
print(name);
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.