I need to inject a DatastoreObject (Twig) into a Locator. The problem is
that the Locator is created by a clazz.newInstance() method so the default
constructor is used.
public class TwigLocator extends Locator<DatastoreObject, Long> {
private ObjectDatastore datastore;
public TwigLocator() {
System.out.println(datastore);
}
@Inject
public TwigLocator(final ObjectDatastore datastore) {
this.datastore = datastore;
}
}
>From LocatorServiceLayer
private <T> T newInstance(Class<T> clazz, Class<? super T> base) {
Throwable ex;
try {
return clazz.newInstance();
} catch (InstantiationException e) {
ex = e;
} catch (IllegalAccessException e) {
ex = e;
}
return this.<T> die(ex,
"Could not instantiate %s %s. Is it default-instantiable?",
base.getSimpleName(), clazz.getCanonicalName());
}
Do you know how I can modify the way the Locator is created? I guess
creating the Locator this way would call the constructor with injection public
TwigLocator(final ObjectDatastore datastore)
private <T> T newInstance(Class<T> clazz, Class<? super T> base) {
return GuiceConfig.getInjectorReference().getInstance(clazz);
}
Thanks
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/GCeBIBTuC8MJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.