Skip to content

Commit

Permalink
Implicit type resolution for inject and get methods
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-kovacs-accedo committed Jan 29, 2024
1 parent 7c1c871 commit a0d892e
Showing 1 changed file with 47 additions and 0 deletions.
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)
}

0 comments on commit a0d892e

Please sign in to comment.