injectzone 0.0.2
injectzone: ^0.0.2 copied to clipboard
Injeczone is a simple and lightweight dependency injection library for Dart that allows you to override dependencies via your type.
Injeczone is a simple and lightweight dependency injection library for Dart that allows you to override dependencies via your type.
Internally Injectzone uses zones and the zoneValues attribute to create or return injected dependencies.
Usage #
To use this package, add injectzone as a dependency in your pubspec.yaml file.
- Inject
Tdependency frombuilderfunction:
final deviceInfo = Injectzone().inject(() => DeviceInfoPlugin());
/// Note: [DeviceInfoPlugin] is a third party dependency
- Override
Tdependency with mock byValueInjectorduringcallbackexecution:
await Injectzone().withInjected([
ValueInjector.inject<DeviceInfoPlugin>(mockDeviceInfoPlugin),
], () {
///... my test code
});
Features and bugs #
Please file feature requests and bugs at the issue tracker.