JAYSH89
10/20/2024, 12:39 PMKoin
).
I was reading the docs specifically on naming:
val myModule = module {
single<Service>(named("default")) { ServiceImpl() }
single<Service>(named("different")) { ServiceImpl() }
}
val service : Service by inject(qualifier = named("default"))
Now I was wondering how would I do this for constructor injection?
I am not using any of the annotation (KSP
) features.
Desired outcome something like:
module { singleOf(::SomeClass) }
class SomeClass(private val defaultService: Service, private val differentService: Service) {}
Alexandru Caraus
10/20/2024, 1:03 PMAlexandru Caraus
10/20/2024, 1:04 PMAlexandru Caraus
10/20/2024, 1:06 PMAlexandru Caraus
10/20/2024, 1:07 PMAlexandru Caraus
10/20/2024, 1:09 PMAlexandru Caraus
10/20/2024, 1:09 PMAlexandru Caraus
10/20/2024, 1:10 PMJAYSH89
10/20/2024, 2:50 PMJAYSH89
10/20/2024, 2:55 PMSpring Boot
I would do something like:
class SomeClass(
@Qualifier("default") private val default: Service,
@Qualifier("different") private val different: Service,
) {}
or in Android + Dagger/Hilt
@Qualifier
annotation class default
@Qualifier
annotation class different
class SomeClass(
@default private val default: Service,
@different private val different: Service,
) {}
JAYSH89
10/20/2024, 3:09 PMwithoutclass
10/21/2024, 1:38 PMwithoutclass
10/21/2024, 1:38 PM