fluttercommunity / get_it

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur
https://pub.dev/packages/get_it
MIT License
1.36k stars 149 forks source link

Error When Registering Multiple Instances with instanceName Using GetIt #388

Closed muhamedsaber closed 1 month ago

muhamedsaber commented 1 month ago

When registering multiple instances of the same type (DioConsumer in this case) with unique instanceName identifiers , an error is encountered when attempting to retrieve these instances. registering them with instanceName values, GetIt throws an error indicating that the object is not registered,


Yellow and Red Bold Pop of Element Vintage Accessories Eyewear Retail Story Ad


GetIt Version: [get_it: ^8.0.0] Flutter Version: [3.24.3] Dart Version: [3.5.3]


Bad state: GetIt: Object/factory with type DioConsumer is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?)

escamoteur commented 1 month ago

Can you please also show the place where you try to access that consumer? I won't claim that there couldn't be a big in get_it but this functionality is absolutely core functions that I use myself all the time. If you could create a small repro project I can debug it. Am 25. Okt. 2024, 20:18 +0100 schrieb mohamed saber @.***>:

When registering multiple instances of the same type (DioConsumer in this case) with unique instanceName identifiers , an error is encountered when attempting to retrieve these instances. registering them with instanceName values, GetIt throws an error indicating that the object is not registered, Yellow.and.Red.Bold.Pop.of.Element.Vintage.Accessories.Eyewear.Retail.Story.Ad.png (view on web) GetIt Version: [get_it: ^8.0.0] Flutter Version: [3.24.3] Dart Version: [3.5.3] Bad state: GetIt: Object/factory with type DioConsumer is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

muhamedsaber commented 1 month ago

FIXED 🎉: Sorry for the mix-up! The issue was due to accessing DioConsumer without specifying its instanceName. GetIt was looking for a default instance, which led to an error. Now, each DioConsumer is correctly accessed using its unique instanceName. Problem solved! 😊