Yes, this is one of the use-cases that assistedinject supports, and there's a lot of tests to make sure it's working as expected. Since you're experiencing a problem with it, the best way to find out what's causing that problem is to isolate it into a reproducible test-case.
sam On Wed, Feb 5, 2014 at 3:53 PM, Rama Krishna Gollapudi <[email protected]>wrote: > I'm not sure. But here is my problem precisely. I'm using an abstract > class inside the factory and bindind that implementation. > Example: > > public interface ResourceFactory { > > Resource domainResource(Domain target); > } > > public abstract class Resource{} > > public MyResource extends Resource{}. > > Where Resource is an abstract. > > and bind them with > install(new FactoryModuleBuilder().implement(Resource.class, > MyResource.class).build( > ResourceFactory.class)); > > Is it possible to bind like this?. > > > > > > > > > > > On Wednesday, 5 February 2014 14:44:05 UTC-6, Sam Berlin wrote: > >> Can you isolate the problem into a repeatable self-contained test-case? >> >> sam >> >> >> On Tue, Feb 4, 2014 at 1:39 PM, Rama Krishna Gollapudi <[email protected] >> > wrote: >> >>> Here is my abstract class >>> >>> public abstract class DomainResource { >>> >>> @Inject >>> @Assisted >>> private Domain target; >>> >>> @Inject >>> private LinkHelper helper; >>> >>> /** >>> * Accessor for the domain resource, will return domain information >>> and links to domain scoped resources >>> * @param info the uri information >>> * @return a Map representing the returned json >>> */ >>> @GET >>> @Produces(APPLICATION_JSON) >>> @SuppressWarnings("nls") >>> public Map<String, Object> get(@Context final UriInfo info) { >>> >>> return "Implement your stuff"; >>> } >>> } >>> >>> >>> *Implementaion* >>> >>> public class TodoResource extends DomainResource { >>> @Inject >>> private Domain domain; >>> @Inject >>> private ScopedResourceFactory factory; >>> @Inject >>> private LinkHelper helper; >>> >>> @GET >>> @Produces(APPLICATION_JSON) >>> public Map<String, Object> getTypes(@Context final UriInfo uriInfo) { >>> return helper.indexMapResponse(); >>> } >>> >>> /** >>> * @param info uriInfo object used to extract matrix params >>> * @return the encounters resource >>> */ >>> @Path("todos") >>> public Object getEncounters(@Context final UriInfo info) { >>> return " implement Your Stuff."; >>> } >>> } >>> >>> >>> *Factory :* >>> public interface ScopedResourceFactory { >>> >>> DomainResource domainResource(Domain target); >>> } >>> >>> >>> >>> And as per your suggestion i'm binding like this. >>> install(new FactoryModuleBuilder().implement(DomainResource.class, >>> TodoResource.class).build( >>> ScopedResourceFactory.class)); >>> >>> But still i'm getting exception. Please find below. >>> >>> >>> >>> com.rama.util.jaxrs.DomainResource is abstract, not a concrete class. >>> Unable to create AssistedInject factory. >>> while locating com.cerner.iaware.util.jaxrs.DomainResource >>> at com.rama.util.guice.ScopedResourceFactory.domainResource( >>> ScopedResourceFactory.java:1) >>> >>> 1 error >>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrors >>> Exist(Errors.java:448) >>> at com.google.inject.internal.InternalInjectorCreator. >>> initializeStatically(InternalInjectorCreator.java:155) >>> at com.google.inject.internal.InternalInjectorCreator.build( >>> InternalInjectorCreator.java:107) >>> at com.google.inject.Guice.createInjector(Guice.java:96) >>> at com.google.inject.Guice.createInjector(Guice.java:73) >>> at com.google.inject.Guice.createInjector(Guice.java:62) >>> at com.rama.todo.guice.GuiceConfigurationInitializer.getInjector( >>> GuiceConfigurationInitializer.java:49) >>> at com.google.inject.servlet.GuiceServletContextListener. >>> contextInitialized(GuiceServletContextListener.java:47) >>> at org.apache.catalina.core.StandardContext.listenerStart( >>> StandardContext.java:4939) >>> at org.apache.catalina.core.StandardContext.startInternal( >>> StandardContext.java:5434) >>> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) >>> at org.apache.catalina.core.ContainerBase$StartChild.call( >>> ContainerBase.java:1559) >>> at org.apache.catalina.core.ContainerBase$StartChild.call( >>> ContainerBase.java:1549) >>> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) >>> at java.util.concurrent.FutureTask.run(FutureTask.java:138) >>> at java.util.concurrent.ThreadPoolExecutor$Worker. >>> runTask(ThreadPoolExecutor.java:886) >>> at java.util.concurrent.ThreadPoolExecutor$Worker.run( >>> ThreadPoolExecutor.java:908) >>> at java.lang.Thread.run(Thread.java:662) >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> On Tuesday, 4 February 2014 12:09:47 UTC-6, Sam Berlin wrote: >>> >>>> The assisted inject >>>> docs<http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/assistedinject/FactoryModuleBuilder.html>describe >>>> how to do this. The example in the doc reads: >>>> >>>> install(new FactoryModuleBuilder() >>>> .implement(Payment.class, RealPayment.class) >>>> .build(PaymentFactory.class)); >>>> >>>> You'd just substitute Payment for DomainResource, RealPayment for >>>> TodoResource, and PaymentFactory for your assistedinject factory. >>>> >>>> sam >>>> >>>> >>>> On Tue, Feb 4, 2014 at 12:38 PM, Rama Krishna Gollapudi < >>>> [email protected]> wrote: >>>> >>>>> Hello, >>>>> I'm having a problem of binding an abstract class with it's >>>>> implementation using Guice . I'm getting the following exception. >>>>> >>>>> com.rama.util.jaxrs.DomainResource is abstract, not a concrete class. >>>>> Unable to create AssistedInject factory. >>>>> >>>>> And i did binding like this. bind(DomainResource.class).to >>>>> (TodoResource.class); >>>>> >>>>> DomainResoruce is an abstract class and TodoResource is an >>>>> implementation. >>>>> >>>>> Thanks, >>>>> Rama. >>>>> >>>>> -- >>>>> 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. >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>> >>>> -- >>> 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. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
