LoginSignup
0
1

More than 3 years have passed since last update.

Koinで2つ以上のインターフェイスを継承しているクラスを注入する方法

Posted at
interface SampleA

interface SampleB

class SampleImpl : SampleA, SampleB

インターフェイスSampleASampleBを継承しているSampleImplKoinで注入します。

val modules = module {

  // 1つのinterface(SampleA)を継承している場合。
  factory<SampleA> { SampleImpl() }

  // 2つ以上のinterface(SampleA/SampleB)を継承している場合。
  factory { SampleImpl() }.binds(SampleA::class, SampleB::class)
}

startKoin {
  androidContext(context)
  modules(modules)
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1