You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by francisco treacy <fr...@gmail.com> on 2008/11/12 11:44:20 UTC

Re: Static injection not working (wicket-guice)

hi,

imho this is a wicket (wicket-guice) issue. we are trying to
accomplish the same as edgar, having the same result:

InjectorHolder.getInjector().inject(this);

java.lang.IllegalStateException: InjectorHolder has not been assigned
an injector. Use InjectorHolder.setInjector() to assign an injector.
In most cases this should be done once inside SpringWebApplication
subclass's init() method.
at org.apache.wicket.injection.web.InjectorHolder.getInjector(InjectorHolder.java:64)

i don't want to use ((GuiceInjectorHolder)
(RequestCycle.get().getApplication().getMetaData(GuiceInjectorHolder.INJECTOR_KEY))).getInjector().injectMembers(this);
because it returns the actual instances - not proxies. and because of
serialization issues this is not desirable in our case.

i tried in my app's init():

		InjectorHolder.setInjector(new ConfigurableInjector() {

			@Override
			protected IFieldValueFactory getFieldValueFactory() {
				return new AnnotProxyFieldValueFactory();
			}
			
		});

with a basic implementation of AnnotProxyFieldValueFactory (copied
from wicket-spring - i don't really know what i'm doing here):

	public class AnnotProxyFieldValueFactory implements IFieldValueFactory {
		
		public Object getFieldValue(Field field, Object fieldOwner) {

			if (field.isAnnotationPresent(Inject.class)) {
				
				// had to wrap this one cause it has package-private visibility
				GuiceBeanLocator locator = new GuiceBeanLocator(field.getType(), null);

				return LazyInitProxyFactory.createProxy(field.getType(), locator);
				
			}
			else
			{
				return null;
			}
		}

		public boolean supportsField(Field field) {
			return field.isAnnotationPresent(Inject.class);
		}
	}


... but i was getting missing binding to guice Provider, so i decided
to stop there :)

are there any workarounds?  kristof and edgar, did you arrive to some
conclusion, perhaps when you emailed privately?
we should be able to use this as we do with spring.  i'm (really)
aware of salve but for some reason we can't use it here.

pointers much appreciated. thanks,

francisco



On Mon, Oct 27, 2008 at 9:27 AM, Kristof Jozsa <kr...@gmail.com> wrote:
> Hi Edgar,
>
> can you share some details with me about what you're trying to
> accomplish? You can write me privately, this doesn't sound like a
> wicket issue so better not load the wicket-users list with the topic.
>
> Kristof
>
> On Wed, Oct 22, 2008 at 8:02 AM, Edgar Merino <do...@gmail.com> wrote:
>> Hello,
>>
>>   I've been trying to inject a service to some classes that are not wicket
>> components, I've asked here and was suggested to use static injection:
>> InjectorHolder.getInjector().inject(this); however this is not working with
>> guice, I always get an illegalstateexception, injectorholder has not been
>> assigned an injector. I've tried ((GuiceInjectorHolder)
>> (RequestCycle.get().getApplication().getMetaData(GuiceInjectorHolder.INJECTOR_KEY))).getInjector().injectMembers(this);
>> however that gives me serialization problems, since wicket is not creating a
>> proxy for my service. I'm on my way to give salve a try but I'm having some
>> problems there too (waiting for a response from the Discussion group), what
>> suggestions can you make?
>>
>> Thanks in advance,
>> Edgar Merino
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org