Hi,

I'm using a Provider to dynamically provide a certain class. The short(ed) 
code : 


public class TemplateConfigurationModule extends AbstractModule {
    
     void configure() {
              
bind(TemplateResolver.class).toProvider(TemplateResolverProvider.class).in(Singleton.class);
     }
}

public class TemplateResolverProvider implements Provider<TemplateResolver> 
{
@Override
public TemplateResolver get() {
String templateResolverClass = .......; /* some logic */
                // FIXME : Wrong. Use the DI
Class<? extends TemplateResolver> templateResolver = 
AppClassloader.classloader().loadClass(templateResolverClass).asSubclass(TemplateResolver.class);
             return 
templateResolver.getDeclaredConstructor(TemplateRendererConfig.class).newInstance(templateRendererConfig);
}
}

public interface TemplateResolver() {
     .. Some stuff
}


public class MockTemplateResolver implements TemplateResolver {
      @Inject
      SomeObject obj;
}

So, the TemplateResolverProvider resolved a TemplateResolver class, which 
then at the end wants to provide a MockTemplateResolver. I've tried two 
things : 

1) Use the normal classloader : In that case, no @Inject gets fullfilled. 
Obviously.
2) Use Guice to give me a TemplateResolver class

The latter also fails : I want it to construct the object and do the 
injections, but it uses the Provider. Also logica.
Then I'm kinda lost : Is there a way to solve this ? For now, I've move the 
@Inject of SomeObject to the Provider, but that doesn't feel right.

Any advise ? 


Regards,


Igmar

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/6687a71a-5a3d-4e6c-87ed-170659d5c2d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to