<div dir="ltr"><div><div><div>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. <br><br></div><div>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 <a href="http://java.io">java.io</a> API provides with chained input/output streams (subclasses of <a href="http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html" title="class in java.io">java.io.InputStream</a>).<br><br></div><div>I think it would make sense to be able to apply decorators to a bean at runtime. <br><br>What do you think about extending <span style="font-family:monospace,monospace"><b>Instance</b></span> class by adding a method like<b> <span style="font-family:monospace,monospace">Instance&lt;T&gt; decorateWith(Class&lt;?&gt; c)</span></b> as in the following example?<br><br></div><div><span style="font-family:monospace,monospace">@Inject<br></span></div><div><span style="font-family:monospace,monospace">Instance&lt;DecoratedInterface&gt; instance;<br>...<br></span></div><div><span style="font-family:monospace,monospace">DecoratedInterface decorated = <br></span></div><div><span style="font-family:monospace,monospace">instance.<b>decorateWith(Decorator1.class)</b><br>        .decorateWith(Decorator2.class)<br></span></div><div><span style="font-family:monospace,monospace">        .get();<br></span></div><div><br></div><div>I haven&#39;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.<br></div><div><br>Ondrej<br></div></div></div></div>