Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#318·auto

AutoFactory: Add a way to inject directly, without Provider

Author: anuraagaCreated Apr 8, 2016Updated May 27, 2024
Labelstype=additionComponent: factoryP3

Currently it's only possible for factory parameters to be injected as Providers. In certain DI frameworks (e.g., spring), Provider#get can be slow (lots of reflection) or even dangerous (dependency graph isn't validated until request processing as opposed to startup).

Make sense to add this?

java
/**
 * An annotation to be applied to parameters that should be provided by an
 * {@linkplain javax.inject.Inject injected} value in a generated factory.
 * Unlike {@link Provided}, this does not use {@link Provider} injection.
 */
@Target(PARAMETER)
public @interface Injected {}

Could also be an option to Provided but naming seems like it'd be clunky.

java
@Provided(direct=true) String hmm,
@Provided(noProvider=true) String maybe,
@Provided(provider=false) String err

Source: google/auto

View original on GitHubView discussion on GitHub