Curious to know if people are passing application ...
# koin
m
Curious to know if people are passing application
Context
in via constructor or just accessing it inline with the help of a top-level property like:
Copy code
val appContext by lazy {
    GlobalContext.get().koin.get<Context>()
}
Since an application
Context
is not mocked (I think!), is there any advantage to passing it into a constructor?
i
I uses Mockito.mock(Application::class.java) for it
m
Could that not be injected into the
GlobalContext
instead of to each constructor?
i
That’s way to the dark side 🙂 Later you can think “why wouldn’t use MyRepo through static member” and so on.
m
I think there’s a big difference there. There’s a good chance I want to provide a mocked MyRepo. Also MyRepo is unlikely to be as pervasive as application Context.
Often I find I have functions that only take an application Context and so without that, I would be able to write
val someValue get() = // something cool
Furthermore, when accepting a Context arg, we cannot be sure if the Context is an application Context or something we should not be holding a reference to (Activity etc), so that complicates things a little.