How to call methods which type are return Module using Kotlin?

247 views Asked by At

I have a two files one.kt and two.kt, i have innerclass in one.kt file. i want to call the that inner class when some action performed like button click in Two.kt file. I tried some of ways the innerclass is called but method does not call. please guide me what i had mistakes. The One.kt file call from manifest file. like this,

<application
        android:name="com.abc.cde.One"

One.kt:

open class One : MultiDexApplication(), KodeinAware {
    ---------------
    --------------
    OnCreate()
    ---------------
    ---------------

inner class CallmyClass() {

        fun CallMyMethod(i: Int) :Module {

            return Module {
                bind<ExchangeRateProvider>() with singleton { CryptoCompareExchangeProvider(this@One, instance()) }
                bind<SyncProgressProvider>() with singleton { SyncProgressProvider() }
                bind<WallethKeyStore>() with singleton { keyStore }
                bind<Settings>() with singleton { KotprefSettings }

                bind<CurrentTokenProvider>() with singleton { CurrentTokenProvider(instance()) }

                bind<AppDatabase>() with singleton { Room.databaseBuilder(applicationContext, AppDatabase::class.java, "maindb").build() }
                bind<NetworkDefinitionProvider>() with singleton { NetworkDefinitionProvider(instance()) }
                //bind<CurrentAddressProvider>() with singleton { InitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext) }
                bind<CurrentAddressProvider>() with singleton { InitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,i) }

                bind<FourByteDirectory>() with singleton { FourByteDirectoryImpl(instance(), applicationContext) }
            }
        }
    }
}

Two.kt:

class Two : AppCompatActivity(), KodeinAware {

    -----------
    -----------
    -----------

    oncreate()

    -------------
    --------------

     val dd = One().CallmyClass().CallMyMethod(1)
}

some blog say you can call this type of methods using this, but i dont know how to use in Activity class because it does not extend Application class.

    override val kodein = Kodein.lazy {
           import(CallMyMethod(1))
    }

i incluse this code in my One.kt file and i want to call from Two.kt file is it possible or not ? guie me please

is it right ? to call like this val dd = One().CallmyClass().CallMyMethod(1). but it does not call my method because of Above the method is return Module type using KodeinAware.

Ref: https://proandroiddev.com/dependency-injection-with-kotlin-kodein-koin-3d783745e48d

UPdate:

private fun CallMyMethod(i: Int) :Module {
                return Module {

                    //bind<ExchangeRateProvider>() with singleton { CryptoCompareExchangeProvider(this@App, instance()) }
                    bind<ExchangeRateProvider>(overrides = true) with singleton { CryptoCompareExchangeProvider(this@App, instance()) }

                    //bind<SyncProgressProvider>() with singleton { SyncProgressProvider() }
                    bind<SyncProgressProvider>(overrides = true) with singleton { SyncProgressProvider() }

                    //bind<WallethKeyStore>() with singleton { keyStore }
                    bind<WallethKeyStore>(overrides = true) with singleton { keyStore }

                    //bind<Settings>() with singleton { KotprefSettings }
                    bind<Settings>(overrides = true) with singleton { KotprefSettings }

                    //bind<CurrentTokenProvider>() with singleton { CurrentTokenProvider(instance()) }
                    bind<CurrentTokenProvider>(overrides = true) with singleton { CurrentTokenProvider(instance()) }

                    //bind<AppDatabase>() with singleton { Room.databaseBuilder(applicationContext, AppDatabase::class.java, "maindb").build() }
                    bind<AppDatabase>(overrides = true) with singleton { Room.databaseBuilder(applicationContext, AppDatabase::class.java, "maindb").build() }

                    //bind<NetworkDefinitionProvider>() with singleton { NetworkDefinitionProvider(instance()) }
                    bind<NetworkDefinitionProvider>(overrides = true) with singleton { NetworkDefinitionProvider(instance()) }

                    //bind<CurrentAddressProvider>() with singleton { DuplicateInitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,1) }
                    bind<CurrentAddressProvider>(overrides = true) with singleton { DuplicateInitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,1) }

                    //bind<FourByteDirectory>() with singleton { FourByteDirectoryImpl(instance(), applicationContext) }
                    bind<FourByteDirectory>(overrides = true) with singleton { FourByteDirectoryImpl(instance(), applicationContext) }
                }
            }

            override val kodein = Kodein {
                //import(CallMyMethod(1), allowOverride = true)
                import(CallMyMethod(1))
            }
0

There are 0 answers