File tree Expand file tree Collapse file tree 8 files changed +103
-3
lines changed
java/ru/otus/daggerhomework Expand file tree Collapse file tree 8 files changed +103
-3
lines changed Original file line number Diff line number Diff line change 1010 android : roundIcon =" @mipmap/ic_launcher_round"
1111 android : supportsRtl =" true"
1212 android : theme =" @style/Theme.DaggerHomework" >
13- <activity android : name =" .MainActivity" >
13+ <activity android : name =" .MainActivity"
14+ android : exported =" true" >
1415 <intent-filter >
1516 <action android : name =" android.intent.action.MAIN" />
1617
Original file line number Diff line number Diff line change @@ -3,4 +3,14 @@ package ru.otus.daggerhomework
33import android.app.Application
44
55class App :Application () {
6+ lateinit var appCompoment: ApplicationComponent
7+ override fun onCreate () {
8+ super .onCreate()
9+ appCompoment = DaggerApplicationComponent .factory().newAppComponent(applicationContext)
10+ }
11+
12+ }
13+
14+ fun Application.asApp (): App {
15+ return this as App
616}
Original file line number Diff line number Diff line change 11package ru.otus.daggerhomework
22
3+ import android.content.Context
4+ import dagger.BindsInstance
5+ import dagger.Component
6+ import javax.inject.Qualifier
7+
8+ @Component
39interface ApplicationComponent {
4- }
10+
11+ @ApplicationContext
12+ fun provideContext (): Context
13+
14+ @Component.Factory
15+ interface Factory {
16+
17+ fun newAppComponent (@ApplicationContext @BindsInstance context : Context ): ApplicationComponent
18+ }
19+ }
20+
21+ @Qualifier
22+ annotation class ApplicationContext
Original file line number Diff line number Diff line change 1+ package ru.otus.daggerhomework
2+
3+ import dagger.Component
4+ import javax.inject.Singleton
5+
6+ @Singleton
7+ @Component(
8+ modules = [FragmentProducerModule ::class ],
9+ dependencies = [ApplicationComponent ::class ]
10+ )
11+ interface FragmentProducerComponent {
12+
13+ companion object {
14+ fun getFragmentProducerComponent (applicationComponent : ApplicationComponent ): FragmentProducerComponent {
15+ return DaggerFragmentProducerComponent .builder()
16+ .applicationComponent(applicationComponent).build()
17+ }
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package ru.otus.daggerhomework
2+
3+ import android.content.Context
4+ import dagger.Module
5+ import dagger.Provides
6+
7+ @Module
8+ interface FragmentProducerModule {
9+ companion object {
10+
11+ @Provides
12+ fun provideContext (@ApplicationContext context : Context ): Context {
13+ return context
14+ }
15+
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package ru.otus.daggerhomework
2+
3+ import dagger.Component
4+
5+ @Component(
6+ modules = [FragmentReceiverModule ::class ],
7+ dependencies = [ApplicationComponent ::class ]
8+ )
9+ interface FragmentReceiverComponent {
10+
11+ companion object {
12+ fun getFragmentReceiverComponent (applicationComponent : ApplicationComponent ): FragmentReceiverComponent {
13+ return DaggerFragmentReceiverComponent .builder()
14+ .applicationComponent(applicationComponent).build()
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package ru.otus.daggerhomework
2+
3+ import android.content.Context
4+ import dagger.Module
5+ import dagger.Provides
6+
7+ @Module
8+ interface FragmentReceiverModule {
9+ companion object {
10+
11+ @Provides
12+ fun provideContext (@ApplicationContext context : Context ): Context {
13+ return context
14+ }
15+
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ package ru.otus.daggerhomework
33import android.app.Application
44import android.content.Context
55import android.widget.Toast
6+ import javax.inject.Inject
67
7- class ViewModelReceiver (
8+ class ViewModelReceiver @Inject constructor (
89 private val context : Context
910) {
1011
You can’t perform that action at this time.
0 commit comments