public <T> T inject( final Class<T> implementation ) { return callInContext(new ContextualCallable<T>() { public T call( InternalContext context ) { return inject(implementation, context); } }); }
public void inject( final Object o ) { callInContext(new ContextualCallable<Void>() { public Void call( InternalContext context ) { inject(o, context); return null; } }); }
public <T> T getInstance( final Class<T> type, final String name ) { return callInContext(new ContextualCallable<T>() { public T call( InternalContext context ) { return getInstance(type, name, context); } }); }
public <T> T getInstance( final Class<T> type ) { return callInContext(new ContextualCallable<T>() { public T call( InternalContext context ) { return getInstance(type, context); } }); }
void injectStatics( List<Class<?>> staticInjections ) { final List<Injector> injectors = new ArrayList<Injector>(); for ( Class<?> clazz : staticInjections ) { addInjectorsForFields(clazz.getDeclaredFields(), true, injectors); addInjectorsForMethods(clazz.getDeclaredMethods(), true, injectors); } callInContext(new ContextualCallable<Void>() { public Void call( InternalContext context ) { for ( Injector injector : injectors ) { injector.inject(context, null); } return null; } }); }
/** * Creates a {@link Container} instance. Injects static members for classes * which were registered using {@link #injectStatics(Class...)}. * * @param loadSingletons If true, the container will load all singletons * now. If false, the container will lazily load singletons. Eager loading * is appropriate for production use while lazy loading can speed * development. * @throws IllegalStateException if called more than once */ public Container create(boolean loadSingletons) { ensureNotCreated(); created = true; final ContainerImpl container = new ContainerImpl( new HashMap<Key<?>, InternalFactory<?>>(factories)); if (loadSingletons) { container.callInContext(new ContainerImpl.ContextualCallable<Void>() { public Void call(InternalContext context) { for (InternalFactory<?> factory : singletonFactories) { factory.create(context); } return null; } }); } container.injectStatics(staticInjections); return container; }