From efe818bf40c144c19d25c4df283996667de84cf4 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Wed, 14 Jul 2010 21:55:48 +0000 Subject: [PATCH] --- .../java/org/wamblee/cdi/SimpleInjector.java | 20 +++++++++++++++++++ .../java/org/wamblee/cdi/MySingleton.java | 5 +++++ .../org/wamblee/cdi/SimpleInjectorTest.java | 1 + .../test/java/org/wamblee/cdi/WeldTest.java | 1 + 4 files changed, 27 insertions(+) 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 -- 2.31.1