Hey :wave: Not exactly related to Koin, but I thin...
# koin
n
Hey 👋 Not exactly related to Koin, but I think this would be the best place to ask for this. I’m using Koin in a KMM library exposing an
initKoin
that is invoked from Android, iOS and NextJs. Android and iOS are OK 👍 . Regarding Next, though, is there anyone who knows what would be the best place to initialise Koin? As you can see, the question is more Next related, but I don’t think there’s a forum in which I can explain fully what’s Koin and everything.
l
Not sure I understand the question. Koin is a dependency injection framework for Kotlin and KMP. It has no driect relevance to iOS or NextJS.
n
So the usual place to initialise the Koin Application in the context of Android is the Application class. In the case of iOS it's the counterpart. What would be the case in a Next app given that some code is run on server and some on the client? That's the question.
p
I think @Nacho Ruiz Martin is asking about what is the best approach to initialize Koin because with NextJS you can be working with Server-side Rendering (SSR) and sometimes with Client-side Rendering (CSR).
Now... wondering about your scenario, Nacho. I think it depends of your business logic. If your library is used to be global for all users, make sense it be on server side. If is something thinking in user logic only (1:1), probably make more sense if it be on client side.
n
Thanks for your answer! It is definitely user logic only since it's the same library that is used for mobile apps (it's the shared code). Now, initialising the code in the client side would mean that the whole application is run on the client side, right? Wouldn't that defeat the purpose of Next?
p
If I'm not wrong, when you're coding an app using NextJS you can work with both rendering approaches (client and server). I suppose your client logic is using only CSR, and in this case make sense to initialize koin only in client side. It's just a guess of my part. I have never used Koin in JS.
n
It's more like a hierarchy of components in which the first parent that is marked as useclient will be rendered itself and all its children in the client side. Since the Koin app would be initialised in the root component, as needed, everything would be rendered on the client side.
Also, I was wondering where to effectively initialise the Koin app so it won't be initialised more than once since components are going to be called several times when they are invalidated, just as Compose functions are recomposed.
I know this is a Next question, just wondering if anyone has the knowledge 🤞
p
Now I got your scenario. Really is tricky. I hope someone can help with this.
n
Thank you! 🙇