[cdi-dev] [JBoss JIRA] (CDI-580) Allow interceptors and decorators to be applied to the return value of a producer method
Antoine Sabot-Durand (JIRA)
issues at jboss.org
Fri Feb 12 03:07:00 EST 2016
[ https://issues.jboss.org/browse/CDI-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13162035#comment-13162035 ]
Antoine Sabot-Durand commented on CDI-580:
------------------------------------------
We discussed this feature during last F2F meeting. My suggestion was to introduce a {{BeanInstanceBuilder}} interface to generate an unmanaged instance for a given {{AnnotatedType}}.
This is inspired by the existing {{UnManaged}} helper class for injecting and calling lifecycle callbacks unmanaged instances.
{{UnManaged}} only uses a class (containing @Inject, @PostConstruct and @Presdetroy annotations) to create instances, {{BeanInstanceBuilder}} would use an {{AnnotatedType}} allowing the use of a synthetic {{AnnotatedType}} containing annotations added by the user like interceptor bindings or {{@Inject}} mentions not present in the original class.
We should forbid or ignore other annotations (scope, qualifier on class
This would allow applying interceptor on a produced class but also interceptor on method in the produced class. And finally it could also be used to have interceptor on custom beans.
Code would look like this
{code}
public class MyAdvancedProducerBean {
public BeanInstanceProducer<MyClass> bip = Builders.beanInstanceProducer();
@Produces
@RequestScoped
public MyClass produceTransactionalMyClass() {
AnnotatedTypeBuilder<MyClass> atb = Builders.annotatedType(Myclass.class)
.read(MyClass.class)
.addToType(new TransactionalLiteral());
return bip.read(atb.build()).inject().postConstruct().intercept().decorate().get(); // injection, callbacks and proxies creation
}
public void disposeMyClass (@Disposes Myclass td) {
bip.dispose(td);
}
}
{code}
The important point is that BeanInstanceProducer is an interface so implementation will use specific proxy feature of Weld or OWB.
wdyt?
> Allow interceptors and decorators to be applied to the return value of a producer method
> ----------------------------------------------------------------------------------------
>
> Key: CDI-580
> URL: https://issues.jboss.org/browse/CDI-580
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Beans
> Affects Versions: 2.0-EDR1
> Reporter: Mark Struberg
>
> Currently the spec explicitly disallows to apply interceptors and decorators to contextual instances created by producer fields and producer methods.
> if you add an Interceptor annotation to a producer method then only the invocation of the producermethod gets intercepted. The created Contextual Instance will remain a plain object.
> We should explore ways to allow this somehow.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the cdi-dev
mailing list