From: erik Date: Wed, 14 Jul 2010 21:55:48 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.3~87 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=3f98ee34653358e951a7bf5a9201545858020a25;p=utils --- diff --git a/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java b/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java index 12ebc307..fff8f113 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java @@ -19,6 +19,26 @@ package org.wamblee.cdi; * Singleton injector access. This should be used as main entry point for * injection. A different {@link InjectorFactory} can be plugged in for testing. * + * Given the following class: + *
 
+ * class Pojo {
+ *   @EJB
+ *   private Service service; 
+ *   
+ *   ...
+ * }
+ * 
+ * injecting the EJB into a POJO is accomplished as follows: + *
+ *   Pojo pojo = new Pojo(); 
+ *   SimpleInjector injector = new SimpleInjector(); 
+ *   injector.inject(pojo);
+ * 
+ * + * Note that it is recommended to cache the injector because the injector does caching + * of the types that it injects into. Caching the injector makes sure that a class is not + * analysed again for annotation every time injection is used. + * * @author Erik Brakkee */ public class SimpleInjector { diff --git a/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java b/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java index 4c597400..5cac7ba7 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java @@ -28,7 +28,12 @@ public class MySingleton { instances++; } + public static void reset() { + instances = 0; + } + public static int getInstances() { return instances; } + } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java index 44c2eda2..61a124a0 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java @@ -36,6 +36,7 @@ public class SimpleInjectorTest { StubInitialContextFactory.register(); InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); + MySingleton.reset(); } @After diff --git a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java index a6d0eb64..57fa4ad2 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java @@ -18,6 +18,7 @@ public class WeldTest { public void setUp() { setup = new BeanManagerSetup(); setup.initialize(); + MySingleton.reset(); } @After