Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi-module with dagger-android after refactor
- Loading branch information
Marcos Holgado
committed
Dec 21, 2018
1 parent
9ec7be8
commit 7cd13ac
Showing
12 changed files
with
83 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/marcosholgado/daggerplayground/di/ActivityBindingModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import com.marcosholgado.daggerplayground.MainActivity | ||
import com.marcosholgado.mymodule.Feature1Module | ||
import com.marcosholgado.mymodule.OtherActivity | ||
import dagger.Module | ||
import dagger.android.ContributesAndroidInjector | ||
|
||
@Module | ||
abstract class ActivityBindingModule { | ||
@ContributesAndroidInjector | ||
abstract fun mainActivity(): MainActivity | ||
|
||
@ContributesAndroidInjector(modules = [Feature1Module::class]) | ||
abstract fun otherActivity(): OtherActivity | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/marcosholgado/daggerplayground/di/AppComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import android.app.Application | ||
import com.marcosholgado.MyApplication | ||
import dagger.Component | ||
import dagger.android.AndroidInjector | ||
import dagger.android.support.AndroidSupportInjectionModule | ||
import dagger.BindsInstance | ||
|
||
@Component(modules = [AppModule::class, | ||
ActivityBindingModule::class, | ||
AndroidSupportInjectionModule::class], | ||
dependencies = [CoreComponent::class] | ||
) | ||
@AppScope | ||
interface AppComponent : AndroidInjector<MyApplication> { | ||
@Component.Builder | ||
interface Builder { | ||
@BindsInstance | ||
fun application(application: Application): AppComponent.Builder | ||
fun coreComponent(coreComponent: CoreComponent): AppComponent.Builder | ||
fun build(): AppComponent | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/marcosholgado/daggerplayground/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import com.marcosholgado.daggerplayground.OtherObject | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
class AppModule { | ||
@Provides | ||
fun provideOtherObject() = OtherObject() | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/marcosholgado/daggerplayground/di/AppScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import javax.inject.Scope | ||
|
||
@Scope | ||
@Retention | ||
annotation class AppScope |
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/marcosholgado/daggerplayground/di/Feature2Component.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
app/src/main/java/com/marcosholgado/daggerplayground/di/Feature2Module.kt
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/marcosholgado/daggerplayground/models.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.marcosholgado.daggerplayground | ||
|
||
class OtherObject |
14 changes: 0 additions & 14 deletions
14
core/src/main/java/com/marcosholgado/core/di/CoreInjectHelper.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
mymodule/src/main/java/com/marcosholgado/mymodule/Feature1Component.kt
This file was deleted.
Oops, something went wrong.
14 changes: 5 additions & 9 deletions
14
mymodule/src/main/java/com/marcosholgado/mymodule/OtherActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
package com.marcosholgado.mymodule | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.marcosholgado.core.ExpensiveObject | ||
import com.marcosholgado.core.di.CoreInjectHelper | ||
import dagger.android.support.DaggerAppCompatActivity | ||
import javax.inject.Inject | ||
|
||
class OtherActivity : AppCompatActivity() { | ||
class OtherActivity : DaggerAppCompatActivity() { | ||
|
||
@Inject | ||
lateinit var expensiveObject: ExpensiveObject | ||
|
||
@Inject | ||
lateinit var text: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_other) | ||
|
||
DaggerFeature1Component | ||
.builder() | ||
.coreComponent(CoreInjectHelper.provideCoreComponent(applicationContext)) | ||
.build() | ||
.inject(this) | ||
} | ||
} |