-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from amzn/rwo/app-scope
Add `AppScope` marker class
- Loading branch information
Showing
4 changed files
with
47 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
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
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
39 changes: 39 additions & 0 deletions
39
...e-optional/src/commonMain/kotlin/software/amazon/lastmile/kotlin/inject/anvil/AppScope.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,39 @@ | ||
package software.amazon.lastmile.kotlin.inject.anvil | ||
|
||
/** | ||
* Scope marker for the application scope, which gets created when the app launches. The | ||
* application scope stays alive as long as the app itself. | ||
* | ||
* To make an object a singleton within the application scope, use this marker class in conjunction | ||
* with [SingleIn], e.g. | ||
* ``` | ||
* @Inject | ||
* @SingleIn(AppScope::class) | ||
* class MyClass : SuperType { | ||
* ... | ||
* } | ||
* ``` | ||
* | ||
* To contribute a component interface to the application scope, use the `ContributesTo` | ||
* annotation: | ||
* ``` | ||
* @ContributesTo(AppScope::class) | ||
* interface AbcComponent { | ||
* @Provides fun provideAbc(): Abc = ... | ||
* | ||
* val abc: Abc | ||
* } | ||
* ``` | ||
* | ||
* To contribute a binding to the application scope, use the `ContributesBinding` annotation: | ||
* ``` | ||
* // Allows you to inject `Service` without adding any Dagger module. | ||
* @Inject | ||
* @ContributesBinding(AppScope::class) | ||
* @SingleIn(AppScope::class) | ||
* class ServiceImpl : Service { | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
public abstract class AppScope private constructor() |