Search code examples
kotlinkoin

What is equivalent Dagger's @Named in Koin?


I'm in the process to moving app from Dagger2 to Koin and need to convert below dagger's

@Provides
@Singleton
@Named("refresh")
fun provideRefreshRetrofit(@Named("refresh") okHttpClient: OkHttpClient, gson: Gson): Retrofit {/*...not important...*/}

till now:

single<Retrofit> { /*....*/ }

but I need to have similar entry in same module. Is a way to convert/solve/workaround it?


Solution

  • See the docs. You can give a name to a definition

    single(name="refresh") { Retrofit.Builder().build() }
    

    and use it

    factory { ClassThatDependsOnRefresh(get("refresh")) } 
    

    Just using single and factory as example here.