Alright I have read through the Guice user-guides and I am using Guice
on several projects now.  I am still pretty new to Guice though.
Currently I have run into a bit of a snag and I wanted some advice on
how to proceed. I don't know how to solve the following issue except
by using static factories (which I know is frowned upon).

Lets say I have a service, 'MyService', which is bound to
'MyServiceImpl', is injected into multiple places in my project, and
is a Singleton (it has state that all parts of the program must be
aware of). So far so good.  This works as expected.

Now one of the places I need access to this service is a class call
'MyGuiScreenController' which implements a third party interface,
'ScreenController'. Now here is where things get interesting.  The
rest of my code never touches MyGuiScreenController.  It is
instantiated (using a default, no argument constructor) by a third
party (GUI) library via reflection.  I have no control over this
process.  It has an inherited method 'bind' which is called when the
GUI is setup, and then any number of methods I define based on GUI
events.

Now as I said, I could probably get away with a static factory and
call said factory inside the bind method to get access to 'MyService',
but is this the only way?  It might get especially ugly as I will
probably have many similar classes to  'MyGuiScreenController', all
needing certain other service classes.  Will I need to make a static
factory for each one of these?  That seems like a bad solution, but
the only one I can figure out at the moment.

Thanks for any help and please ask any questions if I did not explain
myself fully.

~David

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