Hossein Amini
06/21/2021, 10:47 AMTiago Nunes
06/21/2021, 10:59 AMRak
06/21/2021, 11:04 AMJohn O'Reilly
06/21/2021, 11:17 AMJohn O'Reilly
06/21/2021, 11:18 AMJohn O'Reilly
06/21/2021, 11:19 AMKoinComponent
...and there's also koin initialization function that's called from iOS codeHossein Amini
06/21/2021, 3:49 PMGuilherme Delgado
06/22/2021, 9:47 AMHossein Amini
06/22/2021, 9:55 AMGuilherme Delgado
06/22/2021, 10:00 AMGuilherme Delgado
06/22/2021, 10:01 AMGuilherme Delgado
06/22/2021, 10:02 AMJohn O'Reilly
06/22/2021, 10:03 AMGuilherme Delgado
06/22/2021, 10:15 AM// called by iOS etc
fun initKoin(enableNetworkLogs: Boolean) = initKoin(enableNetworkLogs) {}
fun initKoin(enableNetworkLogs: Boolean = false, appDeclaration: KoinAppDeclaration = {}) =
startKoin {
appDeclaration()
modules(commonModule(enableNetworkLogs = enableNetworkLogs))
}
private fun commonModule(enableNetworkLogs: Boolean) = module {
...
single { SettingsApi(get(), PlatformDependencies().baseUrl) }
single { SettingsManager() }
}
Classes:
class SettingsManager: KoinComponent {
private val api: SettingsApi by inject()
...
}
class SettingsApi(private val client: HttpClient, private val baseUrl: String) : KoinComponent {...}
shared/androidMain:
...
lateinit var buildConfigApiUrl: String
actual class PlatformDependencies actual constructor() {
actual val baseUrl: String = buildConfigApiUrl
...
}
module androidApp/…
class App : Application() {
override fun onCreate() {
super.onCreate()
...
buildConfigApiUrl = BuildConfig.API_URL
initKoin(BuildConfig.DEBUG) {
androidLogger()
androidContext(this@App)
}
}
}
Di setup:
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
...
@Provides
// @ViewModelScoped
@Singleton
fun provideSettingsManager() = SettingsManager()
}
@HiltViewModel
class MyViewModel @Inject constructor(
private val settingsManager: SettingsManager,
...
) : ... {
@John O'Reilly Please feel free to comment and validate, this was something that I wanted to bring into discussion. It’s working, but maybe I’m getting here a false positive or it works in this specific use case 😉John O'Reilly
06/22/2021, 10:42 AMSettingsManager
is being separately managed as dependency in both Hilt and Koin?Guilherme Delgado
06/22/2021, 10:57 AMsingle { SettingsManager() }
ends up being the iOSApp DI setup. 🤔Guilherme Delgado
06/22/2021, 10:58 AMJohn O'Reilly
06/22/2021, 10:59 AMGuilherme Delgado
06/22/2021, 11:00 AMJohn O'Reilly
06/22/2021, 11:01 AMJohn O'Reilly
06/22/2021, 11:02 AMGuilherme Delgado
06/22/2021, 11:02 AMGuilherme Delgado
06/22/2021, 11:03 AMJohn O'Reilly
06/22/2021, 11:03 AMGuilherme Delgado
06/22/2021, 11:04 AMGuilherme Delgado
06/22/2021, 11:04 AMGuilherme Delgado
06/22/2021, 11:04 AMGuilherme Delgado
06/22/2021, 11:05 AMGuilherme Delgado
06/22/2021, 11:09 AMobject Jetbrains {
const val kotlin = "1.5.0"
const val kotlinGradlePlugin = "1.5.10"
const val ktor = "1.6.0"
const val kotlinxSerialization = "1.2.1"
const val kotlinxCoroutines = "1.5.0"
const val kotlinxDateTime = "0.2.0"
}
object Core {
const val hilt = "2.37"
const val hiltCompose = "1.0.0-alpha03"
...
}
object Compose {
const val core = "1.0.0-beta09"
const val activity = "1.3.0-beta02"
const val accompanist = "0.12.0"
const val paging = "1.0.0-alpha10"
const val constraintLayout = "1.0.0-alpha08"
const val navigation = "2.4.0-alpha03"
}
object Gradle {
const val buildtools = "7.1.0-alpha02"
}
^ for reference 🙂Kweku
06/23/2021, 10:59 PM