Hey folks,
After a lot of side discussion last year (which I apologize never hit the list), the core dagger team concluded that assisted-injection was, itself, not a core feature of Dagger. But the idea is sound, and it launched the early attempts to put together something more "Daggery", taking in mind the discussion about assisted-injection on this mailing list.
The result was AutoFactory (
https://github.com/google/auto/tree/master/factory) which has been released to maven in an early beta form. That discussion, and dagger's approach in general, sparked a pretty consistent shift in how the core libraries team at google thinks about APIs, and so a more general project
http://github.com/google/auto was created to house AutoFactory, but also other "boiler-plate" generators, such as for simple value objects (AutoValue), java.util.ServiceLoader configuration (AutoService), and possibly more.
Please feel free to try out AutoFactory. At present, it generates a factory for your type annotated with @Provided and mingles injected state and call-stack state to assemble your factory-created type. More or less
@AutoFactory
class Foo {
private final Bar bar;
private final Baz baz;
Foo(@Provided Bar bar, Baz baz) {
...
}
}
gets you:
@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class FooFactory {
private final Provider<Bar> providedBarProvider;
@Inject SomeClassFactory(Provider<Bar> providedBarProvider) {
this. providedBarProvider = providedBarProvider;
}
Foo create(Baz baz) {
return new Foo(providedBarProvider.get(), baz);
}
}
Some options available include
@AutoFactory(
className="CustomFactoryName",
implementing = { MyInterface.class, MyOtherInterface.class },
extending = MyFactorySupertype.class)
class ...
Anyway - please play around with it. There is some more work to be done on it, but I'd like to drive as much future development on AutoFactory from real user needs. So please do file issues, feature requests, etc. Please note we have a lot of documentation to do on AutoFactory. You are warned. :)
Christian.
P.S. A small plug for AutoValue (
https://github.com/google/auto/tree/master/factory) which makes small immutable value type creation trivial with the same inspectability and debuggability that we get from dagger-generated adapters. (Examples are in the docs which have gotten a little more love than AutoFactory docs.