use of jakarta.enterprise.context.Dependent in project core by weld.
the class BeanConfiguratorExtension method afterBeanDiscovery.
void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
event.addBean().scope(Dependent.class).addType(String.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
InjectionPoint ip = i.select(InjectionPoint.class).get();
assertNotNull(ip);
assertNotNull(ip.getBean());
return ip.getBean().getBeanClass().getName();
});
event.addBean().scope(ApplicationScoped.class).addType(Map.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
try {
i.select(InjectionPoint.class).get();
fail("Cannot inject injection point metadata into non-dependent bean");
} catch (IllegalArgumentException expected) {
}
return new HashMap<>();
});
}
use of jakarta.enterprise.context.Dependent in project core by weld.
the class InstanceImpl method destroy.
@Override
public void destroy(T instance) {
checkNotNull(instance);
// Attempt to destroy instance which is either a client proxy or a dependent session bean proxy
if (instance instanceof ProxyObject) {
ProxyObject proxy = (ProxyObject) instance;
if (proxy.weld_getHandler() instanceof ProxyMethodHandler) {
ProxyMethodHandler handler = (ProxyMethodHandler) proxy.weld_getHandler();
Bean<?> bean = handler.getBean();
if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) {
// Destroy internal reference to a dependent session bean
destroyDependentInstance(instance);
return;
} else {
// Destroy contextual instance of a normal-scoped bean
Context context = getBeanManager().getContext(bean.getScope());
if (context instanceof AlterableContext) {
AlterableContext alterableContext = (AlterableContext) context;
alterableContext.destroy(bean);
return;
} else {
throw BeanLogger.LOG.destroyUnsupported(context);
}
}
}
}
// Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy
destroyDependentInstance(instance);
}
use of jakarta.enterprise.context.Dependent in project core by weld.
the class GetContextUtilMethodsTest method getActiveContextsTest.
@Test
public void getActiveContextsTest() {
try (WeldContainer container = new Weld().initialize()) {
// TheLoneBean is just to have some bean in the archive
container.select(TheLoneBean.class).get().ping();
WeldManager manager = container.select(WeldManager.class).get();
// there are 7 scopes by default in SE, only 3 have active contexts by default
// it is dependent, singleton and application
Collection<Context> activeContexts = manager.getActiveContexts();
Assert.assertEquals(3, activeContexts.size());
Set<Class<? extends Annotation>> scopes = activeContexts.stream().map(t -> t.getScope()).collect(Collectors.toSet());
Assert.assertTrue(scopes.contains(Dependent.class));
Assert.assertTrue(scopes.contains(Singleton.class));
Assert.assertTrue(scopes.contains(ApplicationScoped.class));
}
}
Aggregations