Koin: Inject in none activity or fragment

Created on 29 Dec 2019  路  3Comments  路  Source: InsertKoinIO/koin

For injecting in none activity or fragment we use KoinComponent.

When i use this :

class MainClass(private val mContext:Context):KoinComponent {

    private val mMainPresenter:MainPresenter by inject()

    init {

        startKoin {
            androidContext(mContext)
            modules(listOf(
                apiModule,
                repositoryModule,
                dataBaseModule,
                presenterModule,
                viewModule
            ))
        }
    }
.

.

.
}

I faced with this error in run time:

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class de.netalic.mobiletoken.ui.MainFragment, unresolved supertypes: org.koin.core.KoinComponent


> Task :mobiletoken:bundleLibRuntimeDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

My dependencies are:


    //Koin
    implementation "org.koin:koin-android:2.0.1" //i implemented just this
    implementation "org.koin:koin-core-ext:2.0.1"//I try to solve my problem with add these but these are not necessary 
    implementation "org.koin:koin-core:2.0.1"
    implementation "org.koin:koin-android-scope:2.0.1"
    implementation "org.koin:koin-android-ext:2.0.1"
question

Most helpful comment

I could not use KoinComponent finally then i use another way use blow :

  `  val mMainPresenter: MainPresenter by GlobalContext.get().koin.inject()`

@arnaudgiuliani

All 3 comments

I could not use KoinComponent finally then i use another way use blow :

  `  val mMainPresenter: MainPresenter by GlobalContext.get().koin.inject()`

@arnaudgiuliani

unresolved supertypes: org.koin.core.KoinComponent

more a project setup problem?

I think that i faced with this in one project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakuenjery picture dakuenjery  路  4Comments

sankarsana picture sankarsana  路  4Comments

Jeevuz picture Jeevuz  路  4Comments

erikhuizinga picture erikhuizinga  路  3Comments

LukasAnda picture LukasAnda  路  3Comments