*/
public class InjectorFactoryBuilder {
+ private static InjectorFactory FACTORY;
+
+ /**
+ * Sets the injector factory. This is useful for testing.
+ * @param aFactory Factory to use.
+ */
+ public static void setInjectorFactory(InjectorFactory aFactory) {
+ FACTORY = aFactory;
+ }
+
/**
- * Gets the injector factory by using the first one found using
- * {@link ServiceLoader}.
+ * Gets the injector factory by using the first one found using
+ * {@link ServiceLoader}.
*
- * @return InjectorFactory.
+ * @return InjectorFactory.
*/
public static InjectorFactory getInjectorFactory() {
+ if (FACTORY == null) {
+ FACTORY = findInjectorFactory();
+ }
+ return FACTORY;
+ }
+
+ /**
+ * Finds the injector factory musing <code>ServiceLoader</code>
+ *
+ * @return InjectorFactory.
+ */
+ private static InjectorFactory findInjectorFactory() {
ServiceLoader<InjectorFactory> factories = ServiceLoader
.load(InjectorFactory.class);
try {