org.apache.wicket.injection.web
Class InjectorHolder

java.lang.Object
  extended by org.apache.wicket.injection.web.InjectorHolder

public class InjectorHolder
extends java.lang.Object

Holds a reference to the injector that will be used to automatically initialize components that are used. Usually the application class should set the injector in the holder when it initializes.

This class can be used for unit-testing to switch the standard injector with an injector that will lookup dependencies from a mock application context.

 class MockSpringInjector extends SpringInjector
 {
        protected ISpringContextLocator getContextLocator()
        {
                return new MockContextLocator();
        }
 }
 
 InjectorHolder.setInjector(new MockSpringInjector());
 
 //from this point on InjectableWebPage and InjectablePanel
 //will be injected using the MockSpringInjector 
 

Author:
Igor Vaynberg (ivaynberg) TODO shouldn't we move this class to org.apache.wicket.injection ?

Constructor Summary
InjectorHolder()
           
 
Method Summary
static ConfigurableInjector getInjector()
          Gets an injector NOTICE this method is not thread safe if setInjector() is used
static void setInjector(ConfigurableInjector newInjector)
          Sets an injector NOTICE this method is not thread safe.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectorHolder

public InjectorHolder()
Method Detail

getInjector

public static ConfigurableInjector getInjector()
Gets an injector NOTICE this method is not thread safe if setInjector() is used

Returns:
injector

setInjector

public static void setInjector(ConfigurableInjector newInjector)
Sets an injector NOTICE this method is not thread safe.

Parameters:
newInjector - new injector


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.