Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha
Last active January 14, 2018 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalbuddha/79da4d4deb701cf9139aeb4a9c047826 to your computer and use it in GitHub Desktop.
Save digitalbuddha/79da4d4deb701cf9139aeb4a9c047826 to your computer and use it in GitHub Desktop.
//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