Skip to content

Question about injection #121

Answered by czyzby
rmaes4 asked this question in Q&A
Discussion options

You must be logged in to vote

No, the goal is to keep all the initiation complexity in one place and simplify the process. If you want to create objects with DI at runtime, pass the providers (functional objects) to the appropriate constructors.

I know that some of the examples in the README pass the Context around, but this is just an example of its API usage. Normally you'd want to avoid using Context directly other than for the initialization phase.

Let me give you an example:

/** Does a thing. Requires [B] to work. */
class A(val b: B) {
  fun work() {
    b.work()
  }
}

/** A singleton service. */
class B {
  fun work() {
    println("B!")
  }
}

We've got an A class that requires a B instance to work. Let's supp…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by czyzby
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #121 on December 11, 2020 14:27.