I am just wondering, what is a case for clearing s...
# kodein
n
I am just wondering, what is a case for clearing singleton on every request?
j
Not every request, but I have an app that needs to connect to an IoT hotspot. The issue is that the SocketFactory then needs to be reset every time and that has a knock-on effect for every class that relies on an API call (which is most). So I would like the opportunity to say, “I’m changing the network, everyone reset!” Hopefully that makes sense.
s
You also could create a true singleton that doesn’t require a ‘reset’ method. E.g. create your own (singleton) class, called (for example)
ResetableSocketFactory
that uses a
SocketFactory
and handles the ‘resets’ internally only. Then provide that
ResetableSocketFactory
as a singleton dependency. The rest of your code then will use that singleton
ResetableSocketFactory
for the API calls, through Kodein, and resets will be invisible to all of your code (except to the code of your
ResetableSocketFactory
class of course)
n
Thanks for explanation!
j
@streetsofboston Unfortunately, the SocketFactory comes from the Network object itself and that is the thing that OkHttpClient wants specifically (which in turn is what Retrospect wants). I can’t really see a place to jump in the middle. 😞
s
Mmmmm… yeah, that would be tricky, especially since SocketFactory is a (abstract) class, not an interface…