openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r881117 - in /websites/staging/openwebbeans/trunk/content: ./ cdi_explained.html
Date Fri, 04 Oct 2013 09:42:51 GMT
Author: buildbot
Date: Fri Oct  4 09:42:50 2013
New Revision: 881117

Log:
Staging update by buildbot for openwebbeans

Modified:
    websites/staging/openwebbeans/trunk/content/   (props changed)
    websites/staging/openwebbeans/trunk/content/cdi_explained.html

Propchange: websites/staging/openwebbeans/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Fri Oct  4 09:42:50 2013
@@ -1 +1 @@
-1529107
+1529111

Modified: websites/staging/openwebbeans/trunk/content/cdi_explained.html
==============================================================================
--- websites/staging/openwebbeans/trunk/content/cdi_explained.html (original)
+++ websites/staging/openwebbeans/trunk/content/cdi_explained.html Fri Oct  4 09:42:50 2013
@@ -112,42 +112,66 @@ and thus nowadays an integral part of al
 <p>Before we go on to dive into some code, let’s take a quick look at some key
CDI features:</p>
 <ul>
 <li>
-<p>Type Safety: Instead of injecting objects by a (string) name, 
+<p><strong>Type Safety</strong>: Instead of injecting objects by a (string)
name, 
 CDI uses the Java type to resolve injections. When the type is not sufficient, 
 a Qualifier annotation can be used. This allows the compiler to easily detect errors, 
 and provides easy refactoring.</p>
 </li>
 <li>
-<p>POJOs: Almost every Java object can be injected by CDI! 
+<p><strong>POJOs</strong>: Almost every Java object can be injected by
CDI! 
 This includes EJBs, JNDI resources, Persistence Units and Persistence Contexts, 
 as well as any object which previously would have been created by a factory method.</p>
 </li>
 <li>
-<p>Extensibility: Every CDI container can enhance its functionality 
+<p><strong>Extensibility</strong>: Every CDI container can enhance its
functionality 
 by using portable “Extensions”. The attribute “portable” means that 
 those CDI Extensions can run on every CDI container and Java EE 6 server, 
 no matter which vendor. This is accomplished by a well-specified 
 SPI (Service Provider Interface) which is part of the JSR-299 specification.</p>
 </li>
 <li>
-<p>Interceptors: It has never been easier to write your own Interceptors. 
+<p><strong>Interceptors</strong>: It has never been easier to write your
own Interceptors. 
 Because of the portable behaviour of JSR-299, they now also run on every 
 EE 6-certified server and on all standalone CDI containers.</p>
 </li>
 <li>
-<p>Decorators: These allow to dynamically extend existing interface 
+<p><strong>Decorators</strong>: These allow to dynamically extend existing
interface 
 implementations with business aspects.</p>
 </li>
 <li>
-<p>Events: CDI specifies a type-safe mechanism to send 
+<p><strong>Events</strong>: CDI specifies a type-safe mechanism to send

 and receive events with loose coupling.</p>
 </li>
 <li>
-<p>Unified EL integration: EL-2.2 opens a new horizon 
+<p><strong>Unified EL integration</strong>: EL-2.2 opens a new horizon

 in regard of flexibility and functionality. 
 CDI provides out-of-the-box support for it!</p>
 </li>
 </ul>
+<h2 id="a-small-cdi-example">A small CDI Example</h2>
+<p>The following small sample application allows you to send eMails via a web form.
+We will only show code fragments, please checkout our samples form our 
+<a href="source.html">Source Code</a> for more information.</p>
+<h4 id="the-backend">The 'Backend'</h4>
+<p>For our mail application, we need an “application-scoped” MailService.

+Application-scoped objects are essentially singletons – 
+the container will ensure you always get the same single instance whenever 
+you inject it into your application. </p>
+<p>The <code>replyTo</code> address is taken from the ConfigurationService

+which is also application-scoped. Here we see our first injection. 
+The “configuration” field is not set by the application’s code, 
+but is injected by CDI. 
+The <code>@Inject</code> annotation tells CDI to perform the injection.</p>
+<div class="codehilite"><pre><span class="nd">@ApplicationScoped</span>
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">MyMailService</span> <span class="kd">implements</span> <span
class="n">MailService</span> <span class="o">{</span>
+    <span class="kd">private</span> <span class="nd">@Inject</span>
<span class="n">ConfigurationService</span> <span class="n">configuration</span><span
class="o">;</span>
+
+    <span class="kd">public</span> <span class="nf">send</span><span
class="o">(</span><span class="n">String</span> <span class="n">from</span><span
class="o">,</span> <span class="n">String</span> <span class="n">to</span><span
class="o">,</span> <span class="n">String</span> <span class="n">body</span><span
class="o">)</span> <span class="o">{</span>
+        <span class="n">String</span> <span class="n">replyTo</span>
<span class="o">=</span> <span class="n">configuration</span><span
class="o">.</span><span class="na">getReplyToAddress</span><span class="o">();</span>
+        <span class="o">...</span> <span class="c1">// send the email</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
         </div>
 
         <hr>



Mime
View raw message