murt
11/19/2017, 11:04 AMbrainail
11/19/2017, 12:22 PMmurt
11/19/2017, 12:52 PMrkeazor
11/19/2017, 1:36 PMAndreas Sinz
11/19/2017, 1:38 PMrkeazor
11/19/2017, 1:40 PMmurt
11/19/2017, 1:49 PMAndreas Sinz
11/19/2017, 1:57 PMrkeazor
11/19/2017, 2:37 PMAndreas Sinz
11/19/2017, 2:55 PMrkeazor
11/19/2017, 3:11 PMjw
11/19/2017, 3:20 PMmurt
11/19/2017, 3:30 PMAndreas Sinz
11/19/2017, 3:45 PMjw
11/19/2017, 4:06 PMrkeazor
11/19/2017, 4:36 PMAndreas Sinz
11/19/2017, 6:09 PMIn software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object.
rkeazor
11/19/2017, 6:26 PMAndreas Sinz
11/19/2017, 6:54 PMinterface Foo
class FooImpl: Foo
interface Bar
class BarImpl(val foo: Foo): Bar
fun main(args: Array<String>) {
Kodein {
bind<Foo>() with singleton { FooImpl() }
bind<Bar>() with singleton { BarImpl(instance()) }
}
}
KodeinInjected
class MyActivity : Activity(), KodeinInjected {
override val injector = KodeinInjector()
val random: Random by instance()
override fun onCreate(savedInstanceState: Bundle?) {
inject(appKodein())
}
}
rkeazor
11/19/2017, 7:24 PMjw
11/19/2017, 7:38 PMAndreas Sinz
11/19/2017, 8:23 PM@Inject lateinit var random: Random
with val random: Random by instance()
, because DI is meant to decouple the classes from their dependencies. In the end, you either need to import KodeinInjected
(Kodein) or AndroidInjector
(dagger) inside your Activity class, so thats not really decoupling.In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object.
And thats exactly what happens in my first example. The classes get their dependencies through the constructor without knowing where they came from.dave08
11/19/2017, 8:53 PMjw
11/19/2017, 8:57 PMdave08
11/19/2017, 9:05 PMApplication.graph.inject(this)
, with TestApp.graph calls in onCreate, with if (Build.debug) all over?
I know that it shouldn't be tested in general, but in certain cases, I need to assure that things don't get broken...jw
11/19/2017, 9:06 PMdave08
11/19/2017, 9:12 PMobject AndroidInjection
with an if(Build.debug) to know whether to return test graph or real graph? Then it would need an in it fun to be called from the app for building the graph? Is that what you mean?jw
11/19/2017, 10:00 PMdave08
11/20/2017, 3:04 AM