android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.36k stars 11.62k forks source link

Is todo-mvp-kotlin using Dagger for Injection or what? #586

Closed julianonunes closed 5 years ago

julianonunes commented 6 years ago

I'm trying to understand the code from the todo-mvp-kotlin sample, and found calls using an Injection class. The problem is that I could not find any dependencies to Dagger or other DI library, nor any module configuration.

oldergod commented 6 years ago

the todo-mvp-kotlin doesn't use Dagger. If you are interested in the dagger sample, it's over in todo-mvp-dagger

julianonunes commented 6 years ago

So that's an error with the files in the todo-mvp-kotlin repo (e.g.: AddEditTaskActivity.kt, as the activities have an import for the Injection class.

package com.example.android.architecture.blueprints.todoapp.addedittask

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.android.architecture.blueprints.todoapp.Injection
import com.example.android.architecture.blueprints.todoapp.R
import com.example.android.architecture.blueprints.todoapp.util.replaceFragmentInActivity
import com.example.android.architecture.blueprints.todoapp.util.setupActionBar

/**
 * Displays an add or edit task screen.
 */
class AddEditTaskActivity : AppCompatActivity() {
oldergod commented 6 years ago

The injection class is only used here as a service locator. This has nothing to do with Dagger; Dagger is only one way to do dependency injection. The todo-mvp-kotlin uses another one, a manual one.

julianonunes commented 6 years ago

Now I see what's happening. I could not find this injection class as it is in a folder called prod and I was looking only under the main folder.

nibmz7 commented 5 years ago

@julianonunes You can change the build variant to either mock or prod. So the injection class that is used will depend on your build variant. So if you choose the MockDebug variant for instance, it will use the injection class of that in the mock folder. This makes it easy as sometimes you might want to test using dummy data etc.