# android


04/29/2020, 8:51 PM
Hey everyone, as showcased in Google samples making Repository class as Singleton seems to be bit confusing. So as per my understanding a Singleton class doesn't get Garbage collected as it's instance being stored into static variable. Doesn't this seems kind of anti-pattern. Until it's some common repository what's the use case for it to outlive it's scope which may be just within a smaller scope. So what do you guys think?? How many of you consider making Repository class as Singleton. If yes, then I'm really Keen to understand.

Zach Klippenstein (he/him) [MOD]

04/29/2020, 10:08 PM
I agree with your instincts, singletons are an anti-pattern. I’m not sure why the Google samples use them, except that sample code in general tends to simplify wiring details like this. I think it’s pretty common to let your DI library handle scoping for service objects like repositories. It probably makes sense for a lot repositories to be limited to some notion of “logged in scope,” since they presumably need some sort of auth token to make requests.


04/30/2020, 11:21 AM
@Zach Klippenstein (he/him) [MOD] Makes sense.