zef_di_inglue 2.0.1 copy "zef_di_inglue: ^2.0.1" to clipboard
zef_di_inglue: ^2.0.1 copied to clipboard

discontinuedreplaced by: zef_di_core

An adapter for the ZEF_DI_Abstractions package.

example/zef_di_inglue_example.dart

import 'package:zef_di_abstractions/zef_di_abstractions.dart';
import 'package:zef_di_inglue/zef_di_inglue.dart';

import 'test_classes/implementations/index.dart';
import 'test_classes/interfaces/index.dart';

void main() {
  // Build the ServiceLocator
  ServiceLocatorBuilder().withAdapter(InglueServiceLocatorAdapter()).build();

  // Register an Singleton
  ServiceLocator.I.registerSingleton(
    Dolphin(),
    interfaces: {Animal, Fish},
  );

  // Register another Singleton
  ServiceLocator.I.registerSingleton(
    Dolphin(),
    interfaces: {Animal, Fish},
  );

  // Register a Transient
  ServiceLocator.I.registerTransient(
    (serviceLocator, namedArgs) => Whale(),
  );

  // Retrieve the Singleton
  final instance = ServiceLocator.I.resolve<Dolphin>();

  // Retrieve the instance via the interface
  final interfaceInstance = ServiceLocator.I.resolve<Animal>();

  // Do something with the instances
  print(instance.runtimeType); // Output: Dolphin
  print(interfaceInstance.runtimeType); // Output: Dolphin
}
2
likes
140
points
105
downloads

Publisher

verified publisherzooper.dev

Weekly Downloads

An adapter for the ZEF_DI_Abstractions package.

Homepage
Repository (GitHub)
View/report issues

Topics

#dependency-injection #di #injection #ioc #inversion-of-control

Documentation

API reference

Funding

Consider supporting this project:

buymeacoffee.com

License

MIT (license)

Dependencies

any_of, zef_di_abstractions, zef_helpers_lazy

More

Packages that depend on zef_di_inglue