-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ebc2d2
commit 78f3824
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.jvm) | ||
} | ||
apply from: rootProject.file('publishing.gradle') | ||
|
||
kotlin { | ||
explicitApi() | ||
} | ||
|
||
dependencies { | ||
api libs.inject | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_NAME=Anvil Optional Annotations | ||
POM_ARTIFACT_ID=annotations-optional | ||
POM_PACKAGING=jar |
35 changes: 35 additions & 0 deletions
35
annotations-optional/src/main/java/com/squareup/anvil/annotations/optional/ForScope.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import javax.inject.Qualifier | ||
|
||
/** | ||
* A class based [qualfier](Qualifier). | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define qualifier annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @ForScope(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class CommonAuthenticator @Inject constructor() : Authenticator | ||
* | ||
* @ForScope(UserScope::class) | ||
* @ContributesBinding(UserScope::class) | ||
* class UserAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
*/ | ||
@Qualifier | ||
@Retention(RUNTIME) | ||
public annotation class ForScope( | ||
/** | ||
* The marker that identifies the component in which the annotated object is | ||
* provided or bound in. | ||
*/ | ||
val scope: KClass<*>, | ||
) |
40 changes: 40 additions & 0 deletions
40
annotations-optional/src/main/java/com/squareup/anvil/annotations/optional/SingleIn.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import javax.inject.Scope | ||
|
||
/** | ||
* Identifies a type that the injector only instantiates once for the given | ||
* [scope] marker. | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define scope annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Component example: | ||
* ``` | ||
* @SingleIn(AppScope::class) | ||
* @MergeComponent(AppScope::class) | ||
* interface AppComponent | ||
* ``` | ||
* | ||
* Contribution example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @SingleIn(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class RealAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
* | ||
* See Also: [@Scope](Scope) | ||
*/ | ||
@Scope | ||
@Retention(RUNTIME) | ||
public annotation class SingleIn( | ||
/** | ||
* The marker that identifies this scope. | ||
*/ | ||
val scope: KClass<*>, | ||
) |
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