Created
February 23, 2021 14:12
-
-
Save dalexandrov/e5a4743d72eef0184b24ad3ffb3ca121 to your computer and use it in GitHub Desktop.
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
public class Neo4jCdiExtension implements Extension { | |
private static final String NEO4J_METRIC_NAME_PREFIX = "neo4j"; | |
void afterBeanDiscovery(@Observes AfterBeanDiscovery addEvent) { | |
addEvent.addBean() | |
.types(Driver.class) | |
.qualifiers(Default.Literal.INSTANCE, Any.Literal.INSTANCE) | |
.scope(ApplicationScoped.class) | |
.name(Driver.class.getName()) | |
.beanClass(Driver.class) | |
.createWith(creationContext -> { | |
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig(); | |
Config helidonConfig = MpConfig.toHelidonConfig(config).get(NEO4J_METRIC_NAME_PREFIX); | |
ConfigValue<Neo4j> configValue = helidonConfig.as(Neo4j::create); | |
if (configValue.isPresent()) { | |
return configValue.get().driver(); | |
} | |
throw new Neo4jException("There is no Neo4j driver configured in configuration under key 'neo4j"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment