dart_dependency_injection 1.1.3+2 copy "dart_dependency_injection: ^1.1.3+2" to clipboard
dart_dependency_injection: ^1.1.3+2 copied to clipboard

The most powerful dependency injection library for Dart.

example/dart_dependency_injection_example.dart

import 'package:dart_dependency_injection/dart_dependency_injection.dart';

class TestService2 {}

class TestService3 {}

class TestService with DependencyInjectionService {
  void log(String text) {
    getService<TestService2>();
    print(text);
  }
}

class TestObserver extends ServiceObserver with DependencyInjectionService {
  @override
  void onServiceCreated(service) {
    getService<TestService>().log("${service.runtimeType} created");
  }

  @override
  void onServiceDispose(service) {}

  @override
  void onServiceInitializeDone(service) {}
}

void main() async {
  var serviceCollection = ServiceCollection();
  serviceCollection
      .addSingleton<TestService>((serviceProvider) => TestService());
  serviceCollection
      .addSingleton<TestService2>((serviceProvider) => TestService2());
  serviceCollection.addSingleton<TestService3>(
      (serviceProvider) => TestService3(),
      initializeWhenServiceProviderBuilt: true);
  serviceCollection.add<ServiceObserver>((serviceProvider) => TestObserver());
  serviceCollection.build();
}
3
likes
150
pub points
67%
popularity

Publisher

verified publisherybz.im

The most powerful dependency injection library for Dart.

Repository (GitHub)
View/report issues

Topics

#dependency-injection

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, meta

More

Packages that depend on dart_dependency_injection