thenewboston-blockchain / Kotlin-SDK

Kotlin-SDK for thenewboston.
https://thenewboston.com
MIT License
42 stars 19 forks source link

Introduce Dependency Injection Framework or build a Factory pattern #21

Closed MrIceman closed 3 years ago

akulinski commented 3 years ago

@MrIceman do we want to use dagger or koin ?

MrIceman commented 3 years ago

@akulinski What I don't like about koin is that it resolves dependencies at runtime and can cause unexpected bugs, Dagger on the other hand has a big overhead. What do you think about implementing an own factory per module which holds singleton instances of each repository? E.g. object BankFactory { val repository: BankRepository by lazy { BankRepositoryImpl(**Injections**) }  After all, this is what Dagger generates and in a too complicated way imo.

FreedomChuks commented 3 years ago

i dont think we should do this because we have to look at it at scale and it 100 going to grow it best of we use dagger

galalen commented 3 years ago

I agree with @gzodx implementing this from scratch would be hard to scale. If koin causes unexpected bugs then I guess dagger is a better choice

MrIceman commented 3 years ago

Dagger is implemented in Java, our aim is to be multiplatform in future. What about a Kotlin solution? https://github.com/Kodein-Framework/Kodein-DI

Does anyone want to do some research and rate it?

FreedomChuks commented 3 years ago

I don't think dagger being written in java changes anything about it use in multiplaform ,my only problem with koin or Kodein are the fact that they are more of a service locator then a DI lib ,they do all their dependencies graph generation and all on run time which potentially can lead to runtime errors or slow down the app and the main concern once it begins to scale that when it becomes a big overhead to manage

FreedomChuks commented 3 years ago

We don't have to go through dagger 2 over head we can actually use hilt which take 90% of the boilerplate but if KMM if what our focus is then https://github.com/Kodein-Framework/Kodein-DI would be a better solution @MrIceman

MrIceman commented 3 years ago

@gzodx the issue with java code is that it requires a JVM which strikes out iOS and any other platform that has no JVM. Hilt is a wrapper over Dagger. Let's have a look at Kodein

FreedomChuks commented 3 years ago

Okey @MrIceman

IanArb commented 3 years ago

Why don't we just delegate the dependency injection to each platform (i.e. Android and iOS) ?

FreedomChuks commented 3 years ago

The idea to focus on Android first then we target KMM

MrIceman commented 3 years ago

@IanArb from SDK point of view we should offer instances of the specific UseCases / Repositories already to the host app. So the HostApp at the end would only have to call something like TNBClient.bankManager and we'd provide the bank manager instance lazy

khurram-saeed-malik commented 3 years ago

I can create this kind of solution. Will look at in the upcoming weeks and try to build custom factory(ish) pattern to resolve the current challenges and the future ones.

IanArb commented 3 years ago

Hey @khurramsaeed feel free to take this one and looking forward to your solution!

IanArb commented 3 years ago

Hey @khurramsaeed just checking in to see if you need any help?

IanArb commented 3 years ago

Going to close this issue now. We'll be using Dagger.