I don't have a great idea of how your code looks, or to be honest, what exactly you're trying to do, but I'm guessing it's something along the lines of:
* your ORM is instantiating objects * you want those objects to be injected if this is the case, you do have some options: (1) statically inject the classes with an Injector and do what you wish with that (2) decorate the loading with something that has an Injector and can inject the newly created object (2) would be nice if you could get a hook to the loading code. Fred On Fri, Feb 18, 2011 at 9:07 AM, deanhiller <[email protected]>wrote: > Last night, I tried doing creating a CustomProvider BUT then Guice is > not injecting my CustomProvider with fields that have @Inject in my > objects that get created(I was hoping Guice intercepted them and > created them on-demand). Is there a way to make this work.... > > Someone has > @Inject > private Provider<OurCacheListener> listenerProvider; > > and that client that will call listenerProvider.get() only has one > requiremnet. They must set the ThreadLocal var below first so that > the provider knows what object to instantiate, I was hoping to get > Guice to then inject the rest of the dependencies in those created > beans. Is there a way to do this? > > public class ListenerProvider implements Provider<OurCacheListener> { > > private static ThreadLocal<Class<?>> clazzThreadLocal = > new ThreadLocal<Class<?>>(); > > @Override > public OurCacheListener get() { > Class<?> clazz = clazzThreadLocal.get(); > try { > return (OurCacheListener) clazz.newInstance(); > } catch (InstantiationException e) { > throw new RuntimeException("could not construct," + > " see attached exception", e); > } catch (IllegalAccessException e) { > throw new RuntimeException("failed", e); > } > } > > public static void setType(Class<?> clazz2) { > clazzThreadLocal.set(clazz2); > } > > } > > > On Feb 17, 10:11 pm, deanhiller <[email protected]> wrote: > > We have a platform on top of NoSql environment where we have an > > annotation like so on some beans > > > > @CacheListenerImpl(Loader.class) > > or another entity has > > @CacheListenerImpl(Processer.class) > > > > Now the hard part is I don't want to have to code up one line of these > > for each of those lines > > @Inject > > private Provider<Loader> loader; > > > > I would rather has something a bit more dynamic like this > > > > @Inject > > private Provider<CacheListener> provider; > > > > where CacheListener is an interface that Loader, Processor and a whole > > slew of beans implement. Is there a way to do this at all with Guice > > or is this a bit toooooo dynamic for Guice to handle? > > > > OR is there another way in guice more like this perhaps.... > > > > public CacheListener getList(Class c) { > > return someGuiceProvider.create(c); > > > > } > > > > Basically, I want all the created classes to be able to use Guice > > injection as well. > > > > thanks, > > Dean > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > 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-guice?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. 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-guice?hl=en.
