Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little documentation on multi-argument factories #196

Closed
benlancaster opened this issue May 7, 2019 · 4 comments
Closed

Little documentation on multi-argument factories #196

benlancaster opened this issue May 7, 2019 · 4 comments
Labels
type: documentation Issue to fullfil some blank in the documentation
Milestone

Comments

@benlancaster
Copy link

Following on from stackoverflow, there is very scarce documentation on multi-argument factories.

Here's the example I used in the stackoverflow question:

class Injector constructor(secretSauce: SecretSauce) {
    val kodein = Kodein {
        bind<SpicyBeans>() with factory { beans: List<Bean>, herbs: List<Herb> ->
            SpicyBeans(secretSauce, beans, herbs)
        }
    }
}

class SecretSauce

class TastyMeal {
  private lateinit var injector : Kodein
  private lateinit var spicyBeans : SpicyBeans

  fun initialiseWithInjector(kodein : Kodein) {
    injector = kodein
    val herbs = listOf(Coriander(), Cumin())
    val beans = listOf(Pinto(), BlackEyed())
    val tastyDish: SpicyBeans = kodein.direct.instance(arg = M(beans, herbs))
  }
}

val injector = Injector(SecretSauce())
val tastyMeal = TastyMeal().initialiseWithInjector(injector.kodein)
SalomonBrys pushed a commit that referenced this issue May 26, 2019
@edRibeiro
Copy link

Similarly, there are also for factories with multiple arguments.

bind() from factory { id: Long, entity: String -> DetailViewModelFactory(id, entity, instance()) }

direct retrieval to fetch a dependency

private var viewModelFactory: ( (Long, String) -> DetailViewModelFactory) by factory(???) // There is something wrong here that I can not figure out how to properly recover the instance from the factory.

@SalomonBrys
Copy link
Member

Documentation updated.

See #215 for multi-arg factory retrieval.

@SalomonBrys
Copy link
Member

the factoryX functions are not mentioned in the doc.

@romainbsl
Copy link
Member

In fact, it is c694898#diff-3d89743b824a490ce02b697e73924b3bR1102

It will be available with the next release.

@romainbsl romainbsl added this to the 6.4 milestone Jul 16, 2019
@romainbsl romainbsl added the type: documentation Issue to fullfil some blank in the documentation label Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Issue to fullfil some blank in the documentation
Projects
None yet
Development

No branches or pull requests

4 participants