diff --git a/README.md b/README.md index fdcfefca8..f7cf386f4 100644 --- a/README.md +++ b/README.md @@ -45,34 +45,34 @@ dependencies { // Set up your dagger dependencies and compiler // Include this in kotlin or android modules - implementation("se.ansman.dagger.auto:core:1.4.0") - kapt("se.ansman.dagger.auto:compiler:1.4.0") + implementation("se.ansman.dagger.auto:core:1.5.0") + kapt("se.ansman.dagger.auto:compiler:1.5.0") // If you're using KSP - ksp("se.ansman.dagger.auto:compiler:1.4.0") + ksp("se.ansman.dagger.auto:compiler:1.5.0") // Include this in your app module - implementation("se.ansman.dagger.auto:android:1.4.0") + implementation("se.ansman.dagger.auto:android:1.5.0") // Or this in your library module - implementation("se.ansman.dagger.auto:android-api:1.4.0") + implementation("se.ansman.dagger.auto:android-api:1.5.0") // Add these if you want to replace objects during tests - testImplementation("se.ansman.dagger.auto:android-testing:1.4.0") - kaptTest("se.ansman.dagger.auto:compiler:1.4.0") + testImplementation("se.ansman.dagger.auto:android-testing:1.5.0") + kaptTest("se.ansman.dagger.auto:compiler:1.5.0") // If you're using KSP - kspTest("se.ansman.dagger.auto:compiler:1.4.0") + kspTest("se.ansman.dagger.auto:compiler:1.5.0") // If you want to provide Retrofit services add the Retrofit dependency - implementation("se.ansman.dagger.auto:retrofit:1.4.0") + implementation("se.ansman.dagger.auto:retrofit:1.5.0") // If you want to provide Ktorfit services add the Retrofit dependency - implementation("se.ansman.dagger.auto:ktorfit:1.4.0") + implementation("se.ansman.dagger.auto:ktorfit:1.5.0") // If you want to inject a CoroutineScope into ViewModels add the ViewModel dependency - implementation("se.ansman.dagger.auto:androidx-viewmodel:1.4.0") + implementation("se.ansman.dagger.auto:androidx-viewmodel:1.5.0") // If you want to automatically provide your Room DAOs add the Room dependency - implementation("se.ansman.dagger.auto:androidx-room:1.4.0") + implementation("se.ansman.dagger.auto:androidx-room:1.5.0") } ``` diff --git a/gradle.properties b/gradle.properties index e43ef1dda..c20471b10 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ ksp.useKSP2=false android.useAndroidX=true -version=1.5.0-SNAPSHOT -latestRelease=1.4.0 +version=1.5.0 +latestRelease=1.5.0 diff --git a/src/doc/dokka/1.5.0/android/api/index.html b/src/doc/dokka/1.5.0/android/api/index.html new file mode 100644 index 000000000..48dc69557 --- /dev/null +++ b/src/doc/dokka/1.5.0/android/api/index.html @@ -0,0 +1,96 @@ + + +
+ +An Initializer that will initialize a Singleton scoped AutoDaggerStartupInitializer.
This will be called by androidx.startup, provides no result and has no dependencies.
1.0.0
An Initializer that will initialize a Singleton scoped AutoDaggerStartupInitializer.
Denotes that the class referenced using type is to be replaced by this type.
The type to replace must be annotated with AutoBind. Any qualifiers and binding keys will be copied from the referenced type.
The annotated class must implement the types which are bound by the referenced type.
If the replaced type uses multibindings (AutoBindIntoSet or AutoBindIntoMap) then those are only replaced if the annotated type also implements them. Otherwise the multibinding is removed
So for example. If the target type uses @AutoBindIntoSet
to bind it as a Closeable
but your replacement doesn't implement Closeable
then that binding is removed. If it does implement Closeable
then the binding is replaced with the fake binding.
Normally the replacement object needs to be provided to the dependency graph using either an @Provides
annotated method or using an @Inject
annotated constructor.
Auto Dagger allows you to annotate a Kotlin object with @Replaces
without it being provided in the graph. This is especially useful for tests:
@Replaces(ThreadPoolExecutor::class)
object DirectExecutor : Executor {
override fun execute(command: Runnable) {
command.run()
}
}
If the target type is annotated with AutoInitialize, then an empty module will be generated to replace the auto initialize module, effectively disabling it.
// In your `main` source set
interface Repository
@AutoBind(asTypes = [Repository::class])
@AutoBindIntoSet(asTypes = [Closeable::class])
@Singleton
class RealRepository @Inject constructor() : Repository, Closeable {
override fun close() {}
}
// In your `test` source set
// Since `FakeRepository` doesn't implement `Closeable` then it's
// not bound as `Closable` and the real `RealRepository -> Closeable`
// binding is removed.
@Replaces(RealRepository::class)
class FakeRepository @Inject constructor() : Repository
1.0.0
Specifies how generic supertypes should be bound. Defaults to BindGenericAs.ExactType or if the target type is annotated with BindGenericAs.Default.
Which component to install the binding in. Defaults to being inferred based on the scope.
A version of AutoBind that binds the object using IntoMap. The object must also be annotated with a MapKey annotated annotation such as StringKey, MapKey, or a custom annotation.
For more documentation on auto bind see AutoBind.
See also https://dagger.dev/dev-guide/multibindings.html#map-multibindings
1.0.0
Which component to install the binding in. Defaults to being inferred based on the scope.
Specifies which supertypes to bind the object as. Required if there are multiple supertypes.
Specifies how generic supertypes should be bound. Defaults to BindGenericAs.ExactType or if the target type is annotated with BindGenericAs.Default.
Specifies how generic supertypes should be bound. Defaults to BindGenericAs.ExactType or if the target type is annotated with BindGenericAs.Default.
Which component to install the binding in. Defaults to being inferred based on the scope.
A version of AutoBind that binds the object using IntoSet.
For more documentation on auto bind see AutoBind.
See also Set Multibindings
1.0.0
Which component to install the binding in. Defaults to being inferred based on the scope.
Specifies which supertypes to bind the object as. Required if there are multiple supertypes.
Specifies how generic supertypes should be bound. Defaults to BindGenericAs.ExactType or if the target type is annotated with BindGenericAs.Default.
Which component to install the binding in. Defaults to being inferred based on the scope.
Instructs Auto Dagger to automatically bind the annotated type as its parent type.
To use this annotation the class must:
Not be generic - To bind generic types implement your own binding that provides the type arguments.
Have exactly one direct supertype - If you have multiple supertypes then specify which to bind using asTypes.
Only direct supertypes can be bound. For example, if your class implements Closeable
you cannot bind it as AutoCloseable
(which is a supertype of Closeable
). To work around this, add the bound type as an explicit supertype.
interface Repository
@AutoBind
@Singleton
class RealRepository @Inject constructor() : Repository
// Generates the equivalent to:
@Binds
abstract fun RealRepository.bindRealRepositoryAsRepository(): Repository
Auto Dagger tries to infer the component based on the scope of the object using the following mapping:
Scope | Component |
---|---|
No scope | SingletonComponent |
Singleton | SingletonComponent |
Reusable | SingletonComponent |
ActivityRetainedScoped | ActivityRetainedComponent |
ActivityScoped | ActivityComponent |
FragmentScoped | FragmentComponent |
ServiceScoped | ServiceComponent |
ViewScoped | ViewComponent |
ViewModelScoped | ViewModelComponent |
ViewWithFragmentScoped | ViewWithFragmentComponent |
If you want to install the binding in a different component or if you're using a custom scope, then you can use the inComponent parameter to explicit provide the component.
If you have multiple supertypes use the asTypes parameter to specify which of them to bind. You only need to specify the raw class name if the type is generic (i.e. if your type implements Callable<Stuff>
you pass asTypes = [Callable::class]
to indicate you want to bind it).
Normally the bound object needs to be provided to the dependency graph using either an @Provides
annotated method or using an @Inject
annotated constructor.
Auto Dagger allows you to annotate a Kotlin object with @AutoBind
without it being provided in the graph. This is especially useful for tests:
@AutoBind
object DirectExecutor : Executor {
override fun execute(command: Runnable) {
command.run()
}
}
To bind the object using multibinding, use AutoBindIntoSet and/or AutoBindIntoMap. These can be used at the same time as AutoBind.
Any Qualifiers on the annotated type will be carried over to the binding:
@Named("Prod")
@AutoBind
class ProdAuthenticator @Inject constructor() : Authenticator
// Generates the equivalent to:
@Binds @Named("Prod")
abstract fun ProdAuthenticator.bindProdAuthenticatorAsAuthenticator(): Authenticator
1.0.0
Which component to install the binding in. Defaults to being inferred based on the scope.
Specifies which supertypes to bind the object as. Required if there are multiple supertypes.
A class that can initialize multiple Initializable in order of their priority.
1.0.0
If the initializer has been initialized or not (i.e. if initialize has been called).
Initializes the provided Initializable. This method is thread safe and calling it multiple times will only initialize the initializables once.
Returns a new Initializable with the given priority.
Initializes the provided Initializable. This method is thread safe and calling it multiple times will only initialize the initializables once.
If any initializable throws an exception the remaining initializes are still initialized before rethrowing the exception. If multiple initializables throw then the first one is thrown with the other exceptions added as suppressed exceptions.
If this method fails, calling it again will complete successfully without attempting to initialize the failed initializables again.
If the initializer has been initialized or not (i.e. if initialize has been called).
Marks the given objects as being initializable.
This will instruct Auto Dagger to provide the object as an Initializable which allows you to use AutoDaggerInitializer to later initialize the annotated objects.
If the object implements the Initializable interface then it will be created when AutoDaggerInitializer is injected and Initializable.initialize will be called when AutoDaggerInitializer.initialize is called.
Otherwise, the object is only created when AutoDaggerInitializer.initialize is called.
1.0.0
Specifies the default AutoBindIntoSet.bindGenericAs and AutoBindIntoMap.bindGenericAs for the annotated type.
This is useful if you know that the generic is always unique or if it's always shared. For example, an Interceptor<T>
should probably be bound as ExactType because you want to get all interceptors for a given type where as Resource<T>
should probably be bound as Wildcard since you're likely interested in getting all resources because there are no duplicates.
You can only add this to generic types.
Example when using wildcard:
@BindGenericAs.Default(BindGenericAs.Wildcard)
interface Resource<T> {
fun produce(): T
fun close()
}
@AutoBindIntoSet // Will bind this as Resource<*> instead of Resource<SomeThing>
class SomeResource @Inject constructor() : Resource<SomeThing> {
...
override fun close() { ... }
}
class ResourceCloser @Inject constructor(
val resources: Set<@JvmSuppressWildcards Resource<*>>
) {
fun closeAllResources() {
resources.forEach { it.close() }
}
}
Example when using exact type:
@BindGenericAs.Default(BindGenericAs.Type)
interface Interceptor<T> {
fun intercept(value: T): T
}
@AutoBindIntoSet // Will bind this as Interceptor<SomeThing>
class SomeInterceptor @Inject constructor() : Interceptor<SomeThing> {
...
}
class SomeOperation @Inject constructor(
val interceptors: Set<@JvmSuppressWildcards Interceptor<SomeThing>>
) {
fun performOperation(value: SomeThing): SomeThing {
return interceptors.fold(value) { v, interceptor -> interceptor.intercept(v) }
}
}
1.0.0
The type is bound as the exact supertype and as a wildcard type. For example, if the type is List<String>
then it's bound as both List<String>
and List<*>
.
The type is bound as a wildcard type. For example, if the type is List<String>
then it's bound as List<*>
.
Returns a representation of an immutable list of all enum entries, in the order they're declared.
This method may be used to iterate over the enum entries.
How generic types are bound when using multibinding such as AutoBindIntoSet or AutoBindIntoMap.
The default is ExactType unless the bound type is annotated with Default in which case that is used as the default.
1.0.0
Specifies the default AutoBindIntoSet.bindGenericAs and AutoBindIntoMap.bindGenericAs for the annotated type.
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
Returns an array containing the constants of this enum type, in the order they're declared.
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
if this enum type has no constant with the specified name
Returns an array containing the constants of this enum type, in the order they're declared.
This method may be used to iterate over the constants.
Converts the provided Lazy into an Initializable with the given priority (see AutoInitialize.priority).
When the returned Initializable is initialized, the lazy value is computed.
1.0.0
Converts the provided Lazy into an Initializable with the given priority (see AutoInitialize.priority).
Returns a new Initializable with the given priority.
Returns a new Initializable with the given priority.
1.0.0
An interface used to indicate that initialization isn't done when the object is created but rather when calling initialize.
This is useful if you want to be able to test your object.
Although you can use this interface by itself, it's meant to be used in conjunction with AutoInitialize.
1.0.0
Initializes the initializable.
Returns a new Initializable with the given priority.
Initializes the initializable.
Which component to install the binding in. Defaults to being inferred based on the scope.
Denotes that the annotated type might not be provided to the dependency graph.
This will generate a @BindsOptionalOf
binding for the annotated type.
This is useful when the type will only be provided under certain circumstances. For example an Android app might have some debug settings that are only available in debuggable builds.
@OptionallyProvided
interface DebugApi
// This generates
@BindsOptionalOf
abstract fun bindsOptionalDebugApi(): DebugApi
// Then in your implementation module
@AutoBind
@Singleton
class RealDebugApi @Inject constructor() : DebugApi
Auto Dagger tries to infer the component based on the scope of the object using the following mapping:
Scope | Component |
---|---|
No scope | SingletonComponent |
Singleton | SingletonComponent |
Reusable | SingletonComponent |
ActivityRetainedScoped | ActivityRetainedComponent |
ActivityScoped | ActivityComponent |
FragmentScoped | FragmentComponent |
ServiceScoped | ServiceComponent |
ViewScoped | ViewComponent |
ViewModelScoped | ViewModelComponent |
ViewWithFragmentScoped | ViewWithFragmentComponent |
If you want to install the binding in a different component or if you're using a custom scope, then you can use the inComponent parameter to explicit provide the component:
@OptionallyProvided(inComponent = SomeComponent::class)
interface DebugApi
Any Qualifiers on the annotated type will be carried over to the binding:
@Named("Prod")
@OptionallyProvided
interface Authenticator
// Generates the equivalent to:
@BindsOptionalOf
@Named("Prod")
abstract fun bindsOptionalAuthenticator(): Authenticator
1.3.0
Which component to install the binding in. Defaults to being inferred based on the scope.
A version of AutoBind that binds the object using IntoMap. The object must also be annotated with a MapKey annotated annotation such as StringKey, MapKey, or a custom annotation.
A version of AutoBind that binds the object using IntoSet.
A class that can initialize multiple Initializable in order of their priority.
Marks the given objects as being initializable.
How generic types are bound when using multibinding such as AutoBindIntoSet or AutoBindIntoMap.
An interface used to indicate that initialization isn't done when the object is created but rather when calling initialize.
Denotes that the annotated type might not be provided to the dependency graph.