You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gradle recommends using ObjectFactory#newInstance to create new instances of classes as it performs a runtime decoration on the classes. It takes the class to instantiate as the first argument and all of the @Inject annotated constructor arguments as the following arguments.
Unfortunately, AutoFactory is opinionated to use new (with good reason). I'm wondering if we could accommodate cases such as this one where a custom instantiator could be used instead of using new. I would rather not have to maintain a fork of this processor.
Is this something this project would accept as a contribution? If so, which design should we go for? It would be nice to @Provided the instantiator class so it can be used automatically.
The text was updated successfully, but these errors were encountered:
The create methods get the instantiator provider and use an expected method newInstance (for example) by passing the class to instantiate as the first parameter and all the arguments as follow-up arguments, ex:
public Foo create() {
return checkNotNull(_autoFactory_instantiator.get()).newInstance(Foo.class/*, ... */);
}
We can either expect the instantiator to implement an AutoFactory-specific interface or use as-is any object that fit the expected interface aka
<T> T newInstance(Class<T> type, Object... args);
Using instantiator object as-is has the advantage that we can inject current instantiators such as the ObjectFactory from Gradle as it complies with the above interface.
This feature would greatly reduce boilerplate code as well as mostly eliminate out-of-sync issues of those dynamic instantiators between the instantiation point and the constructor arguments list by allowing compile-time failures.
Gradle recommends using
ObjectFactory#newInstance
to create new instances of classes as it performs a runtime decoration on the classes. It takes the class to instantiate as the first argument and all of the@Inject
annotated constructor arguments as the following arguments.Unfortunately, AutoFactory is opinionated to use
new
(with good reason). I'm wondering if we could accommodate cases such as this one where a custom instantiator could be used instead of usingnew
. I would rather not have to maintain a fork of this processor.Is this something this project would accept as a contribution? If so, which design should we go for? It would be nice to
@Provided
the instantiator class so it can be used automatically.The text was updated successfully, but these errors were encountered: