https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kris Wong

11/04/2019, 5:09 PM
is anyone using kodein successfully in a multiplatform library w/ K/N?
i don't see how it could be used given K/N limitations w/ concurrency
k

kpgalligan

11/04/2019, 5:21 PM
It’s single threaded. There will be a koin multithreaded version soon-ish. I have a forked version, although no docs or whatever for now.
k

Kris Wong

11/04/2019, 6:41 PM
yeah I can't think of a scenario where single threaded injection is useful 😛
seems like that should be called out on their website
k

kpgalligan

11/04/2019, 6:42 PM
Well, honestly, I guess it depends how you architect the app
☝️ 1
k

Kris Wong

11/04/2019, 6:54 PM
guess i'll rip that out and go with manual DI for the time being
i've only got a couple things being injected
o

olonho

11/04/2019, 8:59 PM
How DI and concurrency model ever relate to each other?
k

kpgalligan

11/04/2019, 9:05 PM
If the config isn’t static, then it realistically can only be accessed ever on the main thread. You can freeze the config, but would need to be aware that anything in there is also frozen, and then there’s singletons which are (generally) lazy, so the storage needs to be atomic or main thread only. That’s off the top of my head. The DI config and internals aren’t static, so they would need to be main thread only, or internally aware of the KN concurrency model (ie freezable with atomics). If main thread only, I’d assume you’d want something like ensureNeverFrozen and docs about that
I’m not super familiar with kodein, except to say the version I last saw would compile on native but would fail once frozen. I’ve worked on a koin version that would function in native and multiplatform, but still needs finishing (discussing over the next few days, likely, at oredev)
o

olonho

11/04/2019, 9:09 PM
why can’t there be an owner worker for config and all other worker ask for frozen config snapshots?
k

kpgalligan

11/04/2019, 9:09 PM
That would definitely mean the DI framework is aware of Kotlin Native’s model, yes 🙂
You can maybe use something other than atomics, but the way DI works means it needs to be designed in such a way that it’ll work in the native model. I could be totally wrong, but the last kodein version I saw was not designed to be frozen internally (nor the first version of koin multiplatform that was submitted). Also not designed with config isolated in a thread, to be clear
k

Kris Wong

11/04/2019, 9:15 PM
it definitely does not support being frozen
k

Kris Wong

11/04/2019, 9:16 PM
i replaced it with a dirt simple injector that satisfies my use case. it was an interesting exercise getting it to support
by inject()
k

kpgalligan

11/04/2019, 9:18 PM
I still mean to watch this. Kotlin DI without a “framework”. I was there but some Droidcon NYC drama was blowing up so was distracted:

https://www.youtube.com/watch?v=ucZnYS7LmGU&list=PLzJZrgVJE8BZqXB8jXMJOkMJmA1VxxCp7&index=8&t=0s

k

Kris Wong

11/04/2019, 10:12 PM
i'll save you the trouble - the talk is about creating your own object graph using a system of interfaces
classic service locator
in my case I created a simple map of super types to their implementations and use that for property injection using the
by
keyword
i'll be interested once Koin releases multithreaded K/N support
k

Konstantin Petrukhnov

11/05/2019, 5:19 AM
@Kris Wong do you have any code sample?