@KeepMethod public class X_Inject extends Object
Injector.
SingletonDefault or SingletonOverride are usable by X_Inject.
Once a class has been marked as a service provider for a given interface or class,
it can be used in cross-platform code as follows:
@SingletonDefault(implFor=MyService.class)static class MyServiceImpl implements MyService{}
Injector.
JavaInjector, which is based on the
jre6 ServiceLoader, with some tweaks to match the gwt injector behavior.
Files with the name equal to the interface or class being injected are written
to META-INF/singletons for services to be instantiated only once per runtime.
META-INF/instances is for objects that should be new copies for every request.
A third form as META-INF/threadlocal may be provided for thread-local or
process-local services, to help separated code share state without explicit
reference passing. This option will be considered if the concurrency model
is able to offer lifecycle events to ensure the gc of process-local singletons.
JsInjector using AsyncProxy.
See generators.GwtDevGenerator and
its subclass AbstractInjectionGenerator
in the xapi-gwt-inject module.
| Modifier and Type | Method and Description |
|---|---|
static void |
initialize(Object o) |
static <T> T |
instance(Class<? super T> cls) |
static <T> T |
singleton(Class<? super T> cls)
Returns an injected singleton service implementation object.
|
static <T> void |
singletonAsync(Class<? super T> cls,
Class<? extends ReceivesValue<T>> callback) |
static <T> void |
singletonAsync(Class<? super T> cls,
ReceivesValue<T> callback)
Asynchronously loads an injected singleton service implementation object.
|
static <T> javax.inject.Provider<T> |
singletonLazy(Class<? super T> cls)
This is a magic method, like gwt.create.
|
public static void initialize(Object o)
@KeepMethod @MagicMethod(doNotVisit=true) public static <T> T instance(Class<? super T> cls)
@KeepMethod @MagicMethod(doNotVisit=true) public static <T> T singleton(Class<? super T> cls)
singletonAsync(Class, ReceivesValue), then the synchronous providers,
singleton(Class) and singletonLazy(Class) will return null until
the code split containing the service is loaded.
TODO: use AsyncProxy from
If you have ANY doubt about whether a service is already loaded or not,
please prefer the async provider method {@link #singletonAsync(Class, ReceivesValue)
cls - - The service interface / base class to inject.SingletonDefault or SingletonOverride,
and which implements or overrides the service being provided.
@KeepMethod @MagicMethod(doNotVisit=true) public static <T> void singletonAsync(Class<? super T> cls, Class<? extends ReceivesValue<T>> callback)
@KeepMethod @MagicMethod(doNotVisit=true) public static <T> void singletonAsync(Class<? super T> cls, ReceivesValue<T> callback)
singleton(Class) or singletonLazy(Class),
the synchronous methods will return null in gwt production mode until after the split point
is loaded. If you have any doubts about whether a given service is already loaded,
always prefer this asynchronous provider method instead of the sync ones.
cls - - The service interface / base class to inject.callback - - The ReceivesValue to notify when the object is loaded.
SingletonDefault or SingletonOverride,
and which implements or overrides the service being provided.
@KeepMethod @MagicMethod(doNotVisit=true) public static <T> javax.inject.Provider<T> singletonLazy(Class<? super T> cls)
cls - - The interface or base class to be injectedsingletonAsync(Class, ReceivesValue) method.Copyright © December 07, 2012–2015 The Internet Party. All rights reserved.