*/
package org.wamblee.inject;
-import java.util.ServiceLoader;
-
-
/**
- * Singleton injector access. This should be used as main entry point for
- * injection. A different {@link InjectorFactory} can be plugged in for testing.
+ * The main entry point for programmatic dependency injection. A different
+ * {@link InjectorFactory} can be plugged in for testing.
+ *
+ * <p>
+ * Given the following class:
+ * </p>
*
- * Given the following class:
- * <pre>
- * class Pojo {
- * @EJB
- * private Service service;
+ * <pre>
+ * class Pojo {
+ * @EJB
+ * private Service service;
*
- * ...
- * }
+ * ...
+ * }
* </pre>
- * injecting the EJB into a POJO using Contexts and Dependency Injection is accomplished as follows:
+ *
+ * injecting the EJB into a POJO is accomplished as follows:
+ *
* <pre>
- * Pojo pojo = new Pojo();
- * SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory());
- * injector.inject(pojo);
+ * Pojo pojo = new Pojo();
+ * SimpleInjector injector = new SimpleInjector(InjectorFactoryBuilder
+ * .getInjectorFactory());
+ * injector.inject(pojo);
* </pre>
*
- * 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.
+ * Of course, the above example assumes the the injector understands the
+ * @EJB annotation (which of course CDI does).
+ *
+ * The <code>SimpleInjector</code> should be cached. This is because the
+ * <code>SimpleInjector</code> caches the {@link Injector} objects that it uses
+ * internally for performance. This is done because creation of these internal
+ * <code>Injector</code> objects may be costly. Caching the simple injector
+ * makes sure that a class is not analysed again for annotations every time
+ * injection is used.
*
- * The {@link InjectorFactory} to be used can also be found using a {@link ServiceLoader} discovery
- * mechanism as provided by {@link InjectorFactoryBuilder}.
+ * For more advanced cases, the injector factory can also be directly
+ * constructed instead of being obtained through the {@link InjectorBuilder}.
*
* @author Erik Brakkee
*/
-public class SimpleInjector {
+public class SimpleInjector implements Injector {
private InjectorCache cache;
/**
- * Constructs the injector.
- * @param aFactory Factory to use.
+ * Constructs the injector.
+ *
+ * @param aFactory
+ * Factory to use.
*/
- public SimpleInjector(InjectorFactory aFactory) {
+ public SimpleInjector(InjectorFactory aFactory) {
cache = new InjectorCache(aFactory);
}
-
+
/**
* Injects into a given object.
*