singleton_manager 2.2.2 copy "singleton_manager: ^2.2.2" to clipboard
singleton_manager: ^2.2.2 copied to clipboard

High-performance singleton manager for Dart with DI annotations and lazy loading.

example/README.md

Singleton Manager Examples #

Three focused examples showing how to use the singleton_manager package.

1. Basic registry (1_basic_registry.dart) #

  • RegistryManager.instance — the shared registry
  • connectInstance<InterfaceType, InstanceType>(factory) — connect an interface to a concrete factory, invoked lazily on first access
  • getInstance<T>() — resolve (and cache) the connected instance; throws RegistryNotFoundError if nothing is connected
  • getInstanceNullable<T>() — same, but returns null instead of throwing

2. Dependency injection factory (2_dependency_injection_factory.dart) #

Shows the @dependencyInjectable annotation and the dependencyInjectionFactory() factory constructor the generator produces for an annotated class, resolving mandatory constructor parameters via getInstance and nullable named parameters via getInstanceNullable.

3. Subkey-disambiguated dependency injection (3_subkey_dependency_injection.dart) #

Shows the @Subkey('...') annotation, used to resolve dependency injection ambiguity when multiple constructor parameters share the same interface type. Each parameter is tagged with the subkey it must be resolved with (e.g. ipv4/ipv6), and connectInstance/getInstanceNullable are called with the matching subkey to keep the two registrations independent.

Running the examples #

cd packages/singleton_manager
dart run example/1_basic_registry.dart
dart run example/2_dependency_injection_factory.dart
dart run example/3_subkey_dependency_injection.dart
0
likes
160
points
585
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

High-performance singleton manager for Dart with DI annotations and lazy loading.

Repository (GitHub)
View/report issues
Contributing

Topics

#singleton #pattern #dependency-injection #service-locator #resource-management

License

MIT (license)

Dependencies

index_generator

More

Packages that depend on singleton_manager