Hi Tavian,
I'm curious why you think that @Provides method can't handle it. Wouldn't the following be sufficient?
install(new FactoryModuleBuilder()
// this line would tell guice that instances of Foo must come from FooFactory and the provider is only
// to be used by the assisted inject FooFactory proxy
.implement(Foo.class, (Provider<Foo>) getProvider(Foo.class))
.build(FooFactory.class)
@Provides
Foo provideFoo(@Assisted String someRuntimeString) {
return new Foo(someRuntimeString);
}
OR
public class FooProvider implements Provider<Foo> {
private final String someRuntimeString;
@Inject
public FooProvider(final String someRuntimeString) {
this.someRuntimeString = someRuntimeString;
}
@Override
public Foo get() {
return new Foo(this.someRuntimeString);
}
}
//if other code tried to inject either Foo or Provider<Foo> there should be a runtime error stating something like, instances of Foo must be obtained from the assisted inject factory FooFactory.class
I'll admit that in the absence of assisted params, @Provides becomes much more confusing if it's not also eligible to be injected in other contexts. I suppose you could allow it under such circumstances and only yell if assisted params are defined.
Anyway, clearly this feature request needs to be fleshed out a bit more. I don't really have the cycles to implement. Do you happen to know if a tracker exists where I could suggest this as a feature and keep an eye on it should it ever make its way into production?