Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2020-01-17 22:51:26 +05:30
parent 931be3095e
commit 0cde0d4c7f
No known key found for this signature in database
GPG Key ID: C2E74282C2133D62
1 changed files with 8 additions and 17 deletions

View File

@ -16,32 +16,23 @@ I've setup a repository at [msfjarvis/dagger-the-easy-way](https://github.com/ms
## The mandatory theory
I know, I know, I said there won't be any theoretical things here but some parts just have to be explained.
I know what I said, but this is just necessary. Bear with me.
### `Component`
A Component defines an interface that Dagger constructs to know the entry points where dependencies can be injected. It also holds the component factory that instructs Dagger how to construct said component. A Component *also* holds the list of modules.
A Component defines an interface that Dagger constructs to know the entry points where dependencies can be injected. It can also hold the component factory that instructs Dagger how to construct said component. A Component *also* holds the list of modules.
### `Module`
A Module is any logical unit that contributes to Dagger's object graph. In simpler terms, any `class` or `object` that has methods which tell Dagger how to construct a particular dependency, is annotated with `@Module`. Here's a simple code example (that we'll be using later as well).
```kotlin
@Module
object AppModule {
@Reusable
@Provides
fun getSharedPrefs(context: Context): SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
}
```
You'll notice some additional annotations here that I haven't covered yet. These will be explained as we write some code later in this tutorial.
A Module is any logical unit that contributes to Dagger's object graph. In simpler terms, any `class` or `object` that has declarations which tell Dagger how to construct a particular dependency, is annotated with `@Module`.
## Getting Started
To get started, clone the `boilerplate` branch of my repository which contains all the useless grunt work already done for you. Use `git clone --branch boilerplate https://github.com/msfjarvis/dagger-the-easy-way` if you're unfamiliar with branch selection during clone.
The repo in this stage is very bare - it has the usual boilerplate and just one class, `MainActivity`.
The repo in this stage is very bare - it has the usual boilerplate and just one class, `MainActivity`. We're going to make this a bit more interesting shortly.
Switch to the `part-1` branch, which has a bit more in terms of commit history and code. This is what we're going to work with.
## Setting up the things
// TODO: Write the sample project and populate this further.