From d09233c20f885e665e9124760c0318819193e11b Mon Sep 17 00:00:00 2001 From: Piotr <04element_siatka@icloud.com> Date: Mon, 24 Oct 2022 16:54:34 +0200 Subject: [PATCH] add support form type --- lib/get_it.dart | 5 ++++- lib/get_it_impl.dart | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/get_it.dart b/lib/get_it.dart index d7aa6a6..7ba2563 100644 --- a/lib/get_it.dart +++ b/lib/get_it.dart @@ -150,7 +150,7 @@ abstract class GetIt { /// If you really need to you can disable the asserts by setting[allowReassignment]= true bool allowReassignment = false; - /// retrieves or creates an instance of a registered type [T] depending on the registration + /// retrieves or creates an instance of a registered type [T] or [type] depending on the registration /// function used for this type or based on a name. /// for factories you can pass up to 2 parameters [param1,param2] they have to match the types /// given at registration with [registerFactoryParam()] @@ -158,6 +158,7 @@ abstract class GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }); /// Returns a Future of an instance that is created by an async factory or a Singleton that is @@ -168,6 +169,7 @@ abstract class GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }); /// Callable class so that you can write `GetIt.instance` instead of @@ -176,6 +178,7 @@ abstract class GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }); /// registers a type so that a new instance will be created on each call of [get] on that type diff --git a/lib/get_it_impl.dart b/lib/get_it_impl.dart index 7b99d77..07942ab 100644 --- a/lib/get_it_impl.dart +++ b/lib/get_it_impl.dart @@ -391,8 +391,9 @@ class _GetItImplementation implements GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }) { - final instanceFactory = _findFactoryByNameAndType(instanceName); + final instanceFactory = _findFactoryByNameAndType(instanceName, type); Object instance = Object; //late if (instanceFactory.isAsync || instanceFactory.pendingResult != null) { @@ -428,8 +429,9 @@ class _GetItImplementation implements GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }) { - return get(instanceName: instanceName, param1: param1, param2: param2); + return get(instanceName: instanceName, param1: param1, param2: param2, type: type); } /// Returns a Future of an instance that is created by an async factory or a Singleton that is @@ -441,8 +443,9 @@ class _GetItImplementation implements GetIt { String? instanceName, dynamic param1, dynamic param2, + Type? type, }) { - final factoryToGet = _findFactoryByNameAndType(instanceName); + final factoryToGet = _findFactoryByNameAndType(instanceName, type); return factoryToGet.getObjectAsync(param1, param2); }