Hi, I'm new to Guice and I'm trying to convert an existing application
to use guice. Most parts work quite fine, but for one problem I didn't
find a nice solution so far.

I created a little example that hopefully illustrates my problem. I
have a class that depends on a list of SpecialThings and a provider
that itself depends on the *currently active* SpecialThing, i.e., the
provider needs to know what SpecialThing is active when calling get()
because this affects its return value:

    @Inject
    public TestExample(final List<SpecialThing> specials, final
Provider<DependentOnSpecial> provider)
    {
        this.specials = specials;
        this.provider = provider;
    }



    public void run()
    {
        for (final Special currentSpecial : specials)
        {
            final DependentOnSpecial dep = provider.get();
            // provider.setSepcialThing(special); // ???
            for (final String string : dep.elements())
            {
                System.out.println(string);
            }
        }
    }

However, I think this is not the right way how to do it in Guice,
right? I thought about using my own scope but I don't didn't
understand how I can configure the scope with a particular instance of
SpecialThing. SpecialThing is itself not free of dependencies, i.e.,
it cannot be created using no-scope.

Sorry, I got lost in my dependencies somehow :-}

Summarized:
I have a singleton List<SpecialThings>.
I have Components that depend on the currently active, SpecialThing,
i.e., the Injector should inject this active instance to the
providers.

It sounds like needing a scope but how can I achieve this notion of
*active*  SpecialThing from singleton list?
Thanks in Advance.
-- 
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