Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

kotlin multiplatform - Generic types in koin module

I have a class SomeUseCase that requires to provide a T during its init.

class SomeUseCase<T>(
  private val a: A<T>,
  private val b: B<T, Foo>,
  private val c: Repository<Foo>,
)

And I want to use it within Koin module, something like this:

module {
    factory {
        SomeUseCase<T>(
            a = get(),
            b = get(),
            c = get(),
        )
    }
}

It's obvious that I have to pass a type (instead of T). The problem is that instead of T I would like to pass any type of object, for ex: String or Int. Is there a way to do it without defining SomeUseCase 2 times: one for String and other for Int types?

question from:https://stackoverflow.com/questions/65911295/generic-types-in-koin-module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...