New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check if instance of a LazySingle is already created inside of getIt? #257
Comments
Why do you have to check if its created?
Am 15. Feb. 2022, 18:20 +0100 schrieb Muhammet Gazi Salık ***@***.***>:
… GetIt.I.registerLazySingleton(() => CrosswordManager());
I tried to check if an object was created by LazySingleton at least one time but I didn't find it. Because I want to reset the object somewhere.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
@escamoteur because otherwise I get this error:
|
@escamoteur I need to reset those data in somewhere inside of object. |
Do you use resetLazySingleton? Because with that this should not be possible
Am 15. Feb. 2022, 18:28 +0100 schrieb Muhammet Gazi Salık ***@***.***>:
… @escamoteur I need to reset those data in somewhere inside of object.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Yes, I used resetLazySingleton. So why this should not be possible? |
@escamoteur let me explain the scenario. I registered my object as a lazySingleton. I called this object the first time on the third screen in my app but I am calling this object with a parameter. When the user returns to back the second screen and then selects the third screen, I need to reset my singleton object and create it with a different parameter. |
Wouldn't it the not make more sense to use a factory instead of a Singleton?
Am 15. Feb. 2022, 18:45 +0100 schrieb Muhammet Gazi Salık ***@***.***>:
… @escamoteur let me explain the scenario. I registered my object as a lazySingleton. I called this object the first time on the third screen in my app but I am calling this object with a parameter. When the user returns to back the second screen and then selects the third screen, I need to reset my singleton object and create it with a different parameter.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@escamoteur yes it would make more sense. But I tried to use registerFactoryAsync but I got some errors and didn't understand usage. Can you add more examples to this package? |
Do you need an async factory function?
Am 15. Feb. 2022, 23:00 +0100 schrieb mgazisalik ***@***.***>:
… @escamoteur yes it would make more sense. But I tried to use registerFactoryAsync but I got some errors and didn't understand usage. Can you add more examples to this package?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@escamoteur I solved some of issues myself. But I am still getting some error. For example I used registerFactory and registerFactoryAsync to create new object, but when I create new one getIt give me error like this:
What should I do? Maybe I misunderstand something. It would be good if there is a discord channel for this package. Or maybe more example. At least there should be some examples under the functions of descriptions. |
I was misunderstand something. I don't need to create more than one instance of one type. I just need one instance of one type and should be able to reset existing data. I would actually do this manually but I wanted to do this in a more good way because maybe I would forget to reset some data and some bugs can appear in my app. So then I need to know if an instance was created or not. |
it would be nice to make publicly available method _findFactoryByNameAndType |
@mgazisalik you could use a scope for that. Maby my talk https://www.youtube.com/watch?v=YJ52kSfSMyM&list=PL-BFoWYMGZ2TvwY0uf1fBJB1358utBlAz&index=10 will also help you |
@fullflash what's wrong with /// Tests if an [instance] of an object or aType [T] or a name [instanceName]
/// is registered inside GetIt
bool isRegistered<T extends Object>({Object? instance, String? instanceName}); |
isRegistered is checking if class is registered but we were asking for ability to check if instance is created . isRegistered will be true after called registerLazySingleton but how to know if singleton instance is called before. |
Why would you need to know that? The Lazy Singleton guarantees that the instance is available when you first access it
Am 25. Feb. 2022, 19:45 +0100 schrieb fullflash ***@***.***>:
… isRegistered is checking if class is registered but we were asking for ability to check if instance is created .
isRegistered will be true after called registerLazySingleton but how to know if singleton instance is called before.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Can you please provide this api? I still need this. For instance, I have an object and it should be created with lazy. And I need to reset when this object should not be used. Please, I need this api. If you will not provide this api, I will use my own singleton objects and will remove get_it package. |
As noone has brought a conclusve argument why you need this, I close this issue now. If you have to check if your lazy Singleton is already created that feels like a code smell of a bad design to me. |
You are aware that there is a resetLazySingleton function for exactly this use case?
Am 16. März 2022, 15:44 +0100 schrieb mgazisalik ***@***.***>:
… Can you please provide this api? I still need this. For instance, I have an object and it should be created with lazy. And I need to reset when this object should not be used. Please, I need this api. If you will not provide this api, I will use my own singleton objects and will remove get_it package.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
GetIt.I.registerLazySingleton(() => CrosswordManager());
I tried to check if an object was created by LazySingleton at least one time but I didn't find it. Because I want to reset the object somewhere.
The text was updated successfully, but these errors were encountered: