* initialize fields of derived classes to null as these will override the
* initializations of this base class.
*
- * This class uses {@link InjectorFactoryBuilder} to obtain an implementation of
+ * This class uses {@link InjectorBuilder} to obtain an implementation of
* a {@link InjectorFactory} to use.
*
* @author Erik Brakkee
*/
public abstract class Injectable {
- private final SimpleInjector injector =
- InjectorFactoryBuilder.getInjector();
+ private final Injector injector =
+ InjectorBuilder.getInjector();
/**
* Inheritance style constructor.
* Gets the default injector.
* @return Injector.
*/
- public SimpleInjector getInjector() {
+ public Injector getInjector() {
return injector;
}
}
*
* @author Erik Brakkee
*/
-public class InjectorFactoryBuilder {
+public class InjectorBuilder {
private static InjectorFactory FACTORY;
return FACTORY;
}
- public static SimpleInjector getInjector() {
+ /**
+ * Gets an injector that support injection into any type of object and
+ * performs caching of the injector obtained from the {@link InjectorFactory}.
+ * @return Injector.
+ */
+ public static Injector getInjector() {
getInjectorFactory();
return INJECTOR;
}
* testing.
*
* Implementations of this class must have a default no-arg constructor to be usable by
- * {@link InjectorFactoryBuilder}.
+ * {@link InjectorBuilder}.
*
* @author Erik Brakkee
*/
*
* For more advanced cases, the injector factory can also be directly
* constructed instead of being obtained through the
- * {@link InjectorFactoryBuilder}.
+ * {@link InjectorBuilder}.
*
* @author Erik Brakkee
*/
-public class SimpleInjector {
+public class SimpleInjector implements Injector {
private InjectorCache cache;
*
* <p>Users of this package will typically use: </p>
* <ul>
- * <li> <code>SimpleInjector</code>: This is the class used to perform injection of dependencies into
+ * <li> <code>Injector</code>: This is the interface used to perform injection of dependencies into
* a given object. </li>
* <li> <code>Injectable</code>: By subclassing this class, the classes automatically get their
* dependencies injected at construction. </li>
- * <li> <code>InjectorFactoryBuilder</code>: To get an injector factory reference for use in the
- * <code>SimpleInjector</code>
+ * <li> <code>InjectorBuilder</code>: To get an instance of the <code>Injector</code>.
+ * </li>
* </ul>
*
* <h2>Implementors of the package</h2>
* <li> <code>Injector</code>: The main interface to be implemented is the {@link Injector}, by which injection is done.</li>
* <li> <code>InjectorFactory</code>: Injectors are created by an implementation of the {@link InjectorFactory} which
* creates injectors based on the class.</li>
- * <li> <code>InjectorFactoryBuilder</code>: Implementations must make their <code>InjectorFactory</code>
+ * <li> <code>InjectorBuilder</code>: Implementations must make their <code>InjectorFactory</code>
* available through the <code>ServiceLoader</code> mechanism.
* </li>
* </ul>
*/
package org.wamblee.inject;
-
import static org.mockito.Mockito.*;
-public class InjectorFactoryBuilderTest {
+public class InjectorBuilderTest {
@After
public void tearDown() {
- InjectorFactoryBuilder.setInjectorFactory(null);
+ InjectorBuilder.setInjectorFactory(null);
}
@Test
public void testGetInjectorFactory() {
- InjectorFactory factory = InjectorFactoryBuilder.getInjectorFactory();
+ InjectorFactory factory = InjectorBuilder.getInjectorFactory();
assertTrue(factory instanceof TestInjectorFactory);
}
public void testOVerrideInjectorFactory() {
InjectorFactory factory = mock(InjectorFactory.class);
- InjectorFactoryBuilder.setInjectorFactory(factory);
- InjectorFactory factory2 = InjectorFactoryBuilder.getInjectorFactory();
+ InjectorBuilder.setInjectorFactory(factory);
+ InjectorFactory factory2 = InjectorBuilder.getInjectorFactory();
assertSame(factory, factory2);
}
}