Flutterando / auto_injector

Dependency injection system. But without build_runner :)
https://pub.dev/packages/auto_injector
Other
54 stars 15 forks source link

Enable get instance by a String key #13

Closed davidsdearaujo closed 1 year ago

davidsdearaujo commented 1 year ago

What does this PR do

It creates a way to add and get binds by a String key.

Now all the add and get methods have a String? key parameter.

Search functions: When [key] is provided it will search the instance that have the same key

Add functions: When [key] is provided this instance only can be found by key

Changed Functions:

  T get<T>({ParamTransform? transform, String? key});

  T call<T>({ParamTransform? transform, String? key});

  void add<T>(Function constructor, {BindConfig<T>? config, String? key});

  void addInstance<T>(T instance, {BindConfig<T>? config, String? key});

  void addSingleton<T>(Function constructor, { BindConfig<T>? config, String? key});

  void addLazySingleton<T>(Function constructor, {BindConfig<T>? config, String? key});

  dynamic getNotifier<T>({String? key});

  T? tryGet<T>({ParamTransform? transform, String? key});

  bool isAdded<T>({String? key});

  bool isInstantiateSingleton<T>({String? key});

  T? disposeSingleton<T>({String? key});

  void replaceInstance<T>(T instance, {String? key});
toshiossada commented 1 year ago

LGTM

davidsdearaujo commented 1 year ago

@jacobaraujo7 Can you add some tests about this case?

The entire test/src/auto_injector_with_key_test.dart is testing it!