io.smallrye.graphql.cdi.CdiLookupService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smallrye-graphql-cdi Show documentation
Show all versions of smallrye-graphql-cdi Show documentation
Allow lookup up of GraphQL Beans via CDI
package io.smallrye.graphql.cdi;
import jakarta.enterprise.inject.spi.CDI;
import io.smallrye.graphql.spi.LookupService;
import io.smallrye.graphql.spi.ManagedInstance;
/**
* Lookup service that gets the beans via CDI
*
* @author Phillip Kruger ([email protected])
*/
public class CdiLookupService implements LookupService {
@Override
public String getName() {
return "CDI";
}
@Override
public Class> getClass(Class> declaringClass) {
Object declaringObject = getInstance(declaringClass);
return declaringObject.getClass();
}
@Override
public ManagedInstance getInstance(Class declaringClass) {
// getHandle() throws exception if there is unsatisfied or ambiguous dep
return new CDIManagedInstance<>(CDI.current().getBeanContainer().createInstance().select(declaringClass).getHandle());
}
@Override
public boolean isResolvable(Class> declaringClass) {
return CDI.current().select(declaringClass).isResolvable();
}
}