Rick wrote:
> On Mon, Aug 24, 2009 at 8:12 AM, Max Bowsher <[email protected]
> <mailto:[email protected]>> wrote:
> 
>      
>     What you're doing above seems reasonable to me - you'll need to
>     elaborate on "doesn't seem to work" to get help. 
> 
> 
> Thanks Max for your comments...
> 
> As far as "not working" what I end up with is "sqlSession" never being
> bound. Code to illustrate::

[snip]

> In this later case, I never see "setSqlSession" called (and obviously my
> Provider get thus never called either.)

I see nothing wrong with the above code, so.... when all else fails,
construct a simple example that someone else can run to demonstrate the
problem.

Here's a single .java source file which demonstrates something like what
you want:

=======================================================================
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;
import com.google.inject.name.Names;


public class TrivialExample {
    public static void main(String[] args) {
        Guice.createInjector(
            new FooModule()).getInstance(Injectable.class);
    }
}

class Foo {
    public Foo() {
        System.out.println("New object constructed: " + this);
    }
}

class FooProvider implements Provider<Foo> {
    public FooProvider(String initThing) {
        System.out.println("FooProvider created with initThing: "
            + initThing);
    }

    @Override
    public Foo get() {
        return new Foo();
    }
}

class FooModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(Foo.class).annotatedWith(Names.named("wibble"))
            .toProvider(new FooProvider("boing!"));
    }
}

class Injectable {
    @Inject
    public void setSqlSession(@Named("wibble") Foo foo) {
        System.out.println("Injectable injected with: " + foo);
    }
}
=======================================================================

Run it, for me it *does* print "Injectable injected with: ..."

If the above doesn't give you inspiration for what might be wrong, boil
your non-working case down to a similarly small example, and post it here.

Max.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to