Weld SPI offer us the mechanism to bootstrap custom Service by overriding it is Deployment. In a Weld SE environment, we would do the following to bootstrap a custom TransactionService:
weld = new Weld(){
@Override
protected Deployment createDeployment(ResourceLoader resourceLoader, Bootstrap bootstrap)
{
Deployment deployment = super.createDeployment(resourceLoader, bootstrap);
deployment.getServices().add(TransactionServices.class, new InMemoryTransactionServices());
return deployment;
}
};
Though, when using third parties libraries like Arquillian to bootstrap Weld, it is fairly complicated to override the Weld Deployment.
By looking at the Weld 2.0.3.Final source code, especially the WeldBootstrap class, it would be nice if code would lookup for a well known service or system property to init the services.
ex, instead of:
if (!registry.contains(TransactionServices.class))
{
log.info(JTA_UNAVAILABLE);
}
we could do something like:
if (!registry.contains(TransactionServices.class)) {
// first, lookup for a system property
TransactionServices transactionServices = System.getProperty("org.jboss.weld.transaction.spi.TransactionServices");
if (transactionServices != null)
{
registry.getServices().add(TransactionServices.class, transactionServices);
}
// else, lookup for a service
else if (ServiceLoader.load(TransactionServices.class).hasNext())
{
transactionServices = ServiceLoader.load(TransactionServices.class).next();
registry.getServices().add(TransactionServices.class, transactionServices);
}
// then we can safely assume that TransactionServices is really unavailable
else
{
log.info(JTA_UNAVAILABLE);
}
}
By doing so, it would resolve my issue documented in the related forum references.
Thanks,
|