Looking to start adopting new `singleOf` in 3.2.0 ...
# koin
j
Looking to start adopting new
singleOf
in 3.2.0 release. Currently I have likes of following
Copy code
single<PeopleInSpaceRepositoryInterface> { PeopleInSpaceRepository() }
    single { PeopleInSpaceApi(get()) }
PeopleInSpaceApi
also has 2nd default param (url) which seems to cause an issue if I try following (error below). What's recommended way of dealing with this or is it better to use existing
single
for cases like this?.
Copy code
singleOf<PeopleInSpaceRepositoryInterface>(::PeopleInSpaceRepository)
    singleOf(::PeopleInSpaceApi)
Copy code
could not create instance for [Singleton:'com.surrus.common.remote.PeopleInSpaceApi']: org.koin.core.error.NoBeanDefFoundException: |- No definition found for class:'java.lang.String'. Check your definitions!
a
yes with default value in constructor, it will try to fill with get()
then your url is not passed. Either you can pass it as injected param
(or config object)
j
ok, thanks....will take a look at doing something like that
w
@John O'Reilly your URL is of type
String
? Wondering if can make use of a a proper type like
data class ApiUrl(url: String)
(not sure if Koin supports the value class 🤔), then you can actually provide the definition of an
ApiUrl
to Koin and the
get
would resolve it. We've in our project something similar (even we are not using the
singleOf
, to make sure some things are given as it should (and TBH we also use some
named
in some cases to differentiate)
👍 2