Created
May 3, 2019 06:49
-
-
Save seyedjafariy/8b851e292d52f3a9a6e704f0138b08bb to your computer and use it in GitHub Desktop.
creating a CoreComponent in core module
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.Application | |
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import dagger.Component | |
import dagger.Module | |
import javax.inject.Singleton | |
//these live in core module | |
@Module | |
object CoreModule { | |
} | |
@Singleton | |
@Component(modules = [CoreModule::class]) | |
interface CoreComponent { | |
} | |
//these will be in feature module | |
@Module | |
object FeatureModule { | |
} | |
@FeatureScope | |
@Component(dependencies = [CoreComponent::class], modules = [FeatureModule::class]) | |
interface FeatureComponent { | |
fun inject(activity: FeatureActivity) | |
} | |
//created in app module | |
class App : Application() { | |
lateinit var component: CoreComponent | |
override fun onCreate() { | |
super.onCreate() | |
component = DaggerCoreComponent | |
.builder() | |
.build() | |
} | |
} | |
class FeatureActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val appComponent = DaggerCoreComponent | |
.builder() | |
.build() | |
DaggerFeatureComponent.Builder() | |
.coreComponent(coreComponent) | |
.build() | |
.inject(this) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment