Well I am trying to figure out how to do this with...
# multiplatform
y
Well I am trying to figure out how to do this with no di at least.
r
You have a dependency. You're going to have to get it somehow. The strategy isn't going to be all that different from what you'd do in a non-mpp android app. Either make it a constructor parameter of a class that
isLocationAvailable()
is a member of, or you'll need to save a top-level reference to your application during its
onCreate()
☝️ 3
k
or
expect class Context
and pass a
Context
to the function
r
yeah it can be a function parameter instead of a class thing. In practice though I usually see this as part of a
LocationManager
sort of class and it's nice if you can pass the context just once at initialization instead of needing to pass it for every method call
1
y
make it a constructor parameter of a class that
so, as i understand in this case instance should be created on android-platform (app) side and passed to commonMain code?
r
yeah
y
Now i has something like this:
Copy code
class MyApp : Application() {

    override fun onCreate() {
        super.onCreate()
        Core.start()
    }
}
Core - is object in commonMain which (according to my idea) will start “business logic processing” But it seems it should look like Core.start(thousands of ContextWrapper, LocationManagerWrapper, whateverPlatformSpecieficWrapper) Am I right?
r
Oh if you already have an injection point like that it helps. You could just define
fun Core.start(/* Android dependencies */)
in your Android sources and
fun Core.start(/* iOS dependencies*/)
on iOS, and wire whatever platform-specific stuff you need in there
Might just be
Core.start(applicationContext)
on Android and
Core.start()
on iOS if that's the only dependency you have
If it starts getting unwieldy, that's where having some sort of dependency manager is helpful
y
Something seems to have cleared up 🙂 thank you!
👍 1