[cdi-dev] API to chain Decorators programmatically?

Ondrej Mihályi ondrej.mihalyi at gmail.com
Sat May 28 17:24:28 EDT 2016


I think that Decorators are a great concept in CDI, but it cannot provide
solution to a wide variety of problems where the general decorator pattern
makes sense.

AFAIK, it is not possible to chain decorators at runtime, in order to reuse
the decorator mechanism to solve class explosion problem and create a
flexible architecture, similar to what java.io API provides with chained
input/output streams (subclasses of java.io.InputStream
<http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html>).

I think it would make sense to be able to apply decorators to a bean at
runtime.

What do you think about extending *Instance* class by adding a method like*
Instance<T> decorateWith(Class<?> c)* as in the following example?

@Inject
Instance<DecoratedInterface> instance;
...
DecoratedInterface decorated =
instance.*decorateWith(Decorator1.class)*
        .decorateWith(Decorator2.class)
        .get();

I haven't find a way to do something similar using the current API, nor did
I find any third-party CDI extension to provide something similar.

Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20160528/8dbc4442/attachment.html 


More information about the cdi-dev mailing list