All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.graphql.cdi.CdiLookupService Maven / Gradle / Ivy

There is a newer version: 2.11.0
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy