Last active
January 14, 2018 19:06
-
-
Save digitalbuddha/79da4d4deb701cf9139aeb4a9c047826 to your computer and use it in GitHub Desktop.
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
//Main Idea: Rather than declaring subcomponents you declare Scopes which contain modules | |
//Holster is a processor which will generate a subcomponent for each scope and | |
//allows you to get a reference to each component through a generated Locator. | |
//Difference with Dagger Android is that we create the child/parent component | |
//relationship in the scope annotation rather than depending on @ContributesAndroidInjector/HasInjector | |
@MyActivityScope(ActivityModule::class, child=MyViewScope::class) | |
class MyActivity{ | |
@inject aDep:ADep | |
onCreate(){ inject()) } | |
} | |
@MyViewScope(ViewModule::class) | |
class MyView{ | |
init{ | |
inject() | |
} | |
} | |
var Activity.component | |
get() = Injector.lazyGetComponentFor(this) | |
var View.component | |
get() = Injector.lazyGetComponentFor(this) | |
fun Activity.inject(){ | |
component.inject(this) | |
} | |
fun View.inject(){ | |
view.component().inject(this); | |
} | |
@Generated | |
//creates/gets a subcomponent for each instances from a | |
//generated map of component factories | |
fun Injector.lazyGetComponentFor(injectRoot:Activity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment