An attempt at a presentation explaining how to implement Dagger 2 without using Thermosiphons and Coffee machines as examples. Link to corresponding repo:
github.com/patrykpoborca/CleanArchitecture
started and talk about what DI is, and how to use Dagger 2. To first understand DI, you must understand the principle of inversion of control. In essence it’s the idea that your class should be given any (complex) classes it depends on, and not create them. Dependency Injection is a software design pattern that implements inversion of control for resolving dependencies.
edges, each edge connecting one vertex to another, such that there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again. ~Wikipedia
“apis” and not utilize actual APIs: OKHttp - For fake requests Retrofit - To fake processing requests (Constructor takes OKHttp) LocalDataCache - To fake writing to disk (LDC takes Context in Constructor) TweeterAPI - The goal of our little application (Takes Retrofit and LocalDatacache)
a complex structure behind the scenes which also contains a factory, allowing you to do things like this: CleanArchitectureApplication.getTweeterAPIComponent() . getTwitterAPI();
observed, I never made a method in my NetworkModule which provides a TweeterAPI This is because Dagger 2 can infer what it can provide based on objects with injectable constructors, so if you look back at the implementation of TweeterAPI you can inject that object into your code:
will likely be instantiating a new TweeterAPI/OKHttp/Retrofit instance. That’s where scope comes in. You simply tag your components and Modules with an annotation.