Thread
#multiplatform
    Kris Wong

    Kris Wong

    2 years ago
    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
    kpgalligan

    kpgalligan

    2 years ago
    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.
    Kris Wong

    Kris Wong

    2 years ago
    yeah I can't think of a scenario where single threaded injection is useful 😛
    seems like that should be called out on their website
    kpgalligan

    kpgalligan

    2 years ago
    Well, honestly, I guess it depends how you architect the app
    Kris Wong

    Kris Wong

    2 years ago
    guess i'll rip that out and go with manual DI for the time being
    i've only got a couple things being injected
    olonho

    olonho

    2 years ago
    How DI and concurrency model ever relate to each other?
    kpgalligan

    kpgalligan

    2 years ago
    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)
    olonho

    olonho

    2 years ago
    why can’t there be an owner worker for config and all other worker ask for frozen config snapshots?
    kpgalligan

    kpgalligan

    2 years ago
    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
    Kris Wong

    Kris Wong

    2 years ago
    it definitely does not support being frozen
    Kris Wong

    Kris Wong

    2 years ago
    i replaced it with a dirt simple injector that satisfies my use case. it was an interesting exercise getting it to support
    by inject()
    kpgalligan

    kpgalligan

    2 years ago
    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

    Kris Wong

    Kris Wong

    2 years ago
    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

    2 years ago
    @Kris Wong do you have any code sample?