The library requires your app's minSdk
to be 21+
plugins {
alias(libs.plugins.ksp)
}
dependencies {
implementation("me.tawsif.hilt:flexible-hilt-core:0.60")
ksp("me.tawsif.hilt:flexible-hilt-compiler:0.60")
}
Make your base class/interface inherit FlexibleHiltItem
class Pet @Inject constructor(): FlexibleHiltItem {
val type = "dog"
}
interface Human: FlexibleHiltItem {
val profession: String
}
fun printPetType(pet: Pet = FlexibleHilt.get()) {
println(pet.type)
}
Note: There's also FlexibleHilt.getLazy()
which you can use to get a lazy instance of the class.
Helpful in Activity
classes where you can only use hilt classes after super.onCreate()
Copyright (c) 2024 Dewan Tawsif
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.