Created
October 15, 2019 09:44
-
-
Save juliuscanute/a74923d7208342e98b088bd1af794b75 to your computer and use it in GitHub Desktop.
[ContributeAndroidInjector] #dagger #subcomponent #activityscope
This file contains hidden or 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
import dagger.Module | |
// required imports | |
@Module | |
class ActivityBuilderModule{ | |
@ActivityScope | |
@ContributeAndoridInjector(modules = [ActivityModule::class]) | |
fun bindFeatureActivity(): FeatureActivity | |
} |
This file contains hidden or 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
import dagger.Module | |
import dagger.Provides | |
@Module(include = [FragmentBuilderModule::class] | |
class ActivityModule { | |
@Provides | |
fun providePresenter(): FeatureActivityPresenter = FeatureActivityPresenter() | |
@ActivityScope | |
@Provides | |
fun provideFoo(): Foo = Foo() | |
} |
This file contains hidden or 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
@Component(modules = [ActivityBuilderModule::class) | |
public interface AppComponent{ | |
fun inject(application: Application); | |
} |
This file contains hidden or 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
import android.app.Activity | |
import android.os.Bundle | |
import javax.inject.Inject | |
class FeatureActivity : Activity() { | |
@Inject | |
lateinit var featureActivityPresenter: FeatureActivityPresenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
AndroidInjection.inject(this) | |
super.onCreate(savedInstanceState) | |
} | |
} |
This file contains hidden or 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
import android.app.Fragment | |
import android.content.Context | |
import javax.inject.Inject | |
class FeatureFragment : Fragment() { | |
@Inject | |
lateinit var featureFragmentPresenter: FeatureFragmentPresenter | |
override fun onAttach(context: Context?) { | |
AndroidSupportInjection.inject(this) | |
super.onAttach(context) | |
} | |
} |
This file contains hidden or 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
import dagger.Module | |
// required imports | |
@Module | |
class FragmentBuilderModule { | |
@FragmentScope | |
@ContributeAndoridInjector(modules = [FragmentModule::class]) | |
fun bindFeatureFragment(): FeatureFragment | |
} |
This file contains hidden or 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
import dagger.Module | |
import dagger.Provides | |
@Module | |
class FragmentModule { | |
@FragmentScope | |
@Provides | |
fun providePresenter(foo: Foo, bar: Bar): | |
FeatureFragmentPresenter = FeatureFragmentPresenter(foo) | |
@Provides | |
fun provideBar(): Bar = Bar() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment