Skip to content

Commit

Permalink
improved java injector
Browse files Browse the repository at this point in the history
  • Loading branch information
Suqatri committed Jul 9, 2024
1 parent 80dc8f0 commit aa99c88
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions apis/base-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.net.URI

plugins {
`maven-publish`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package dev.redicloud.api.utils

import kotlinx.coroutines.runBlocking

class CloudJKWrapper {

companion object {
@JvmStatic
fun injectCloudAPI(cloudInjectable: CloudInjectable) {
cloudInjectable.injectCloudApi()
fun injectCloudAPI(clazz: Class<out CloudInjectable>, cloudInjectable: CloudInjectable) {
injectCloudAPI(clazz, cloudInjectable)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import com.google.inject.Injector
lateinit var injector: Injector

inline fun <reified T : CloudInjectable> T.injectCloudApi() {
val membersInjector = injector.getMembersInjector(T::class.java)
membersInjector.injectMembers(this)
injectCloudApi(T::class.java, this)
}

fun <T : CloudInjectable> injectCloudApi(clazz: Class<T>, instance: T) {
val membersInjector = injector.getMembersInjector(clazz)
membersInjector.injectMembers(instance)
}

interface CloudInjectable

0 comments on commit aa99c88

Please sign in to comment.