Dagger 2 for Dummies in Kotlin — Subcomponent

We learned about @Scope in my previous blog. We can see that it is tied to a @Component. It allow us to create a scoped object and reuse it the next time. For un-scoped object, a new one is always recreated.

But having one @Scope is not sufficient for a bigger project. Especially for project in Android, we do have Activities and then have Fragments. We need something that not live forever, but also not always got recreated anew.

Good news, this blog is to show you how to do that, with the most simple example (Just one Activity, no Fragment… that’s why this is a blog for dummies😝).

Recap about @Scope

In case you wonder what I’m talking about @Scope, you could refers to my blog below.

In that blog, we have a sample code. It ihas a MagicBox that could inject two type of objects, i.e. UniqueMagic and NormalMagic as shown in diagram below.

--

--