-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implicit type resolution for inject and get methods
- Loading branch information
1 parent
7c1c871
commit a0d892e
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
android/koin-android/src/main/java/org/koin/android/ext/koin/KoinJavaComponentExt.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,47 @@ | ||
package org.koin.android.ext.koin | ||
|
||
import org.koin.java.KoinJavaComponent | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency lazily, without explicit type specification. | ||
*/ | ||
inline fun <reified T> inject(): Lazy<T> { | ||
return KoinJavaComponent.inject(T::class.java) | ||
} | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency lazily if available, without explicit type specification. | ||
*/ | ||
inline fun <reified T> injectOrNull(): Lazy<T?> { | ||
return KoinJavaComponent.injectOrNull(T::class.java) | ||
} | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency, without explicit type specification. | ||
*/ | ||
inline fun <reified T> get(): T { | ||
return KoinJavaComponent.get(T::class.java) | ||
} | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency if available, without explicit type specification. | ||
*/ | ||
inline fun <reified T> getOrNull(): T? { | ||
return KoinJavaComponent.getOrNull(T::class.java) | ||
} | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency, without explicit type specification. | ||
* @param clazz - dependency class | ||
*/ | ||
inline fun <reified T> get(clazz:Class<T>): T { | ||
return KoinJavaComponent.get(clazz) | ||
} | ||
|
||
/** | ||
* Wrapped call to retrieve given dependency if available, without explicit type specification. | ||
* @param clazz - dependency class | ||
*/ | ||
inline fun <reified T> getOrNull(clazz:Class<T>): T? { | ||
return KoinJavaComponent.getOrNull(clazz) | ||
} |