Bob,

This assumes that by the time you perform your chaining, you've
already created an Injector. What if I want to specify a Provider
inside a module even before I've created any injector for the first
time?

Essentially, my problem is this:

class FooWrapper {
  private final Dependancy1 dependancy1;
  private final Dependancy2 dependancy2;
  private final RuntimeDependancy runtimeDependancy;
  @Inject
  public FooWrapper(...) {

  }
}

So the first two depenancies I know at compile time but the third is
only known at runtime.

Furthermore, the creation of FooWrapper is something that I want to
configure INSIDE Bar:

class Bar {
  private final FooWrapper fooWrapper;
  @Inject
  public Bar(FooWrapper fooWrapper) {
    this.fooWrapper = fooWrapper;
  }

  public Foo createFoo(RuntimeDependancy runtimeDependancy) {
    return new FooWrapper(..., ..., runtimeDependancy); // <== heres
the problem
  }
}

So, what I'd effectively like to do is have guice inject only part of
the dependencies at start-up and allow me to provide another component
at runtime. Conceivably, something like a provider that takes
arguments:

RuntimeProvider<T> {
  <T> get(Object ... args);
}

This would allow me to implement Bar as follows:

class Bar {
  private final FooWrapper fooWrapper;
  @Inject
  public Bar(FooWrapper fooWrapper) {
    this.fooWrapper = fooWrapper;
  }

  public Foo createFoo(RuntimeDependancy runtimeDependancy) {
    return runtimeProvider.get(runtimeDependancy);
  }
}

This way, I could wire up everything inside my modules and still have
only 1 injector, and not have to do anything after the first injector
is created...

Is there anyway to do this with guice currently?

Nathan

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