kiwi 5.0.1 copy "kiwi: ^5.0.1" to clipboard
kiwi: ^5.0.1 copied to clipboard

A simple yet efficient dependency injection container for Dart and Flutter (can be coupled with the kiwi_generator package).

example/kiwi_example.dart

import 'package:kiwi/kiwi.dart';

main() {
  KiwiContainer container = KiwiContainer();

  container.registerInstance(Logger());
  container.registerSingleton((c) => Logger(), name: 'namedLogger');
  container.registerFactory(
      (c) => ServiceA(logger: c.resolve<Logger>('namedLogger')));

  final comumLogger = container.resolve<Logger>();
  final namedLogger = container.resolve<Logger>('namedLogger');
  final serviceA = container.resolve<ServiceA>();

  print(comumLogger.toString()); // Hey, I'm a logger!
  print(namedLogger.toString()); // Hey, I'm a logger!
  print(serviceA.toString()); // Hey, I'm a service A!
}

class Service {
  const Service();

  @override
  String toString() {
    return 'Hey, I\'m a service!';
  }
}

class ServiceA extends Service {
  final Logger logger;

  const ServiceA({required this.logger});

  @override
  String toString() {
    return 'Hey, I\'m a service A!';
  }
}

class Logger {
  const Logger();

  @override
  String toString() {
    return 'Hey, I\'m a logger!';
  }
}
161
likes
160
pub points
95%
popularity

Publisher

verified publishergbtb16.com.br

A simple yet efficient dependency injection container for Dart and Flutter (can be coupled with the kiwi_generator package).

Repository (GitHub)
View/report issues

Topics

#deep-linking #dependency-injector #containers

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on kiwi