infusion

Last updated:

0 purchases

infusion Image
infusion Images
Add to Cart

Description:

infusion

Infusion - Dependency Injection #
A light weight dependency injector that can be used with any dart project.
Features #

Transient & singleton services
Named services
Support for service providers/factories

Getting started #
Add dependency to pubspec.yaml then run dart pub get
dependencies:
infusion: ^0.1.0
copied to clipboard
Usage #
import 'package:infusion/infusion.dart';

class Implementation implements Interface {
...
}

class ImplementationB implements Interface {
...
}

class Service {
final Interface impl;
final Interface implB;

Service(this.impl, @Named("another") this.implB)
}

void main() {
final container = Container();

// Add service 'Implementation' that implements 'Interface' to container
container.addService<Interface, Implementation>();

// Add service 'Implementation' named 'another' that implements 'Interface' to container
container.addService<Interface, ImplementationB>(identifier: "another");

container.getService<Interface>(); // Returns Implementation;
container.getService<Interface>(identifier: "another"); // Returns ImplementationB;
}
copied to clipboard
Additional information #
A larger example can be found in example/infusion_example.dart

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.