We are trying to convert out project to Guice, and have transitioned
from MyBatis-Spring to MyBatis-Guice.  Everything is working fine with
that.  However now I need my higher level object to be created with
Guice so it can create the data access objects, that is where I run
into problems.  I'm looking for advice on how to get this to work with
Guice, or if I need to rewrite it in a less generic way.

I have a class that manages threads and each thread has delegates for
retrieving jobs and executing jobs.  I tell the type of job to these
objects, so I can use them for all the different kinds of jobs.  I
want to be able to use Guice to create my delegate objects (and
threads) but those are all generic and need to be of the same type as
the containing class.  The issue I'm running into isn't the binding,
but getting Guice to try and request the right class.  If I can get
this to work I think it will be slick as the particular job processor
can just bind the delegates for its particular job and they will be
injected into this generic workflow.
I could just pass around a base object but then I would have to cast
to get my specific job, but I don't like that solution.  I've seen
references to TypeLiteral<T> as an injected parameter to the
constructor of a generic object while looking at posts about generics
and Guice.  However I haven't found any examples of how this can help,
or how to get this to work.

I've simplified the classes so its easier to understand.

class ThreadManager<T extends Job>
{


        public start(int numThreads)
        {
                for (int x = 0; x < numThreads; x++)
                {
                        threads.add(getJobThread());
                }
        }

        private JobThread<T> getJobThread()
        {
                // return a new JobThread based on the generic type param T
        }
}

public class JobThread<T extends Job> extends Thread
{
        @Inject
        private JobRetriever<T> retriever;
        @Inject
        private JobExecutionDelegate<T> executionDelegate;

        public void doSomeWork()
        {
                T job = retreiver.getJob();
                executionDelegate.executeJob(job);
        }
}

Thanks!
 - Nealio

-- 
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.

Reply via email to