org.wamblee.inject
Class InjectorBuilder

java.lang.Object
  extended by org.wamblee.inject.InjectorBuilder

public class InjectorBuilder
extends java.lang.Object

Utility for obtaining an implementation of the InjectorFactory using ServiceLoader and for obtaining a SimpleInjector. The builder takes care that the factory and simple injector are built only once. For test code, make sure to call setInjectorFactory(InjectorFactory) before each test case to force the retrieval of a new factory and injector. This is important because if the simple injector is not created again it will use cached Injector instances from other tests.

Author:
Erik Brakkee

Constructor Summary
InjectorBuilder()
           
 
Method Summary
static Injector getInjector()
          Gets an injector that support injection into any type of object and performs caching of the injectors obtained from the InjectorFactory.
static InjectorFactory getInjectorFactory()
          Gets the injector factory by using the first one found using ServiceLoader.
static void setInjectorFactory(InjectorFactory aFactory)
          Sets the injector factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectorBuilder

public InjectorBuilder()
Method Detail

setInjectorFactory

public static void setInjectorFactory(InjectorFactory aFactory)
Sets the injector factory. This is useful for testing.

Parameters:
aFactory - Factory to use.

getInjectorFactory

public static InjectorFactory getInjectorFactory()
Gets the injector factory by using the first one found using ServiceLoader.

Returns:
InjectorFactory.

getInjector

public static Injector getInjector()
Gets an injector that support injection into any type of object and performs caching of the injectors obtained from the InjectorFactory.

Returns:
Injector.


Copyright © 2022. All Rights Reserved.