Skip to content

Commit

Permalink
Added some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Peal committed May 22, 2022
1 parent bdc67cf commit 31a0780
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.gpeal.droidconanvilsample.lib.daggerscopes

/**
* Adds api to the @AppComponent graph. Equivalent to the following declaration in an application module:
* Annotate a retrofit interface with this to automatically contribute it to the [AppScope] graph.
* Equivalent to the following declaration in an application module:
*
* @Provides
* @Reusable
* public fun provideYourApi(retrofit: Retrofit): YourApi = retrofit.create(YourApi::class.java)
*
* The generated code created via the :anvilcodegen module.
*/
@Target(AnnotationTarget.CLASS)
annotation class ContributesApi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@ package com.gpeal.droidconanvilsample.lib.daggerscopes
import javax.inject.Scope
import kotlin.reflect.KClass

// This could live in a shared library module.
/**
* This annotation lets you use the same annotation to represent which scope you want to contribute an Anvil object to
* and also as `@SingleIn(YourScope::class)`.
*
* Without `@SingleIn`, an AppComponent contribution might look like this:
* ```
* @Singleton
* @ContributesBinding(AppScope::class)
* class YourClassImpl : YourClass
* ```
* Singleton is a well defined pattern for AppScope but the scope naming becomes more confusing once you start defining your
* own components.
* `@SingleIn` prevents you from memorizing two names per component. The above example becomes:
* ```
* @SingleIn(AppScope::class)
* @ContributesBinding(AppScope::class)
* class YourClassImpl : YourClass
* ```
*
* And custom components would look like:
* ```
* @SingleIn(YourScope::class)
* @ContributesBinding(YourScope::class)
* class YourClassImpl : YourClass
* ```
*/
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class SingleIn(val clazz: KClass<*>)

0 comments on commit 31a0780

Please sign in to comment.