Skip to content

ENH: Add support for using @Prototype on @Factory @Bean methods #214

@rbygrave

Description

@rbygrave
@Factory
class AppConfig {

  @Prototype
  @Bean
  MyBuilder newBuilder() {
    return new MyBuilder();
  }
}

We can inject a Provider<T> like below. Each provider.get() will return a new instance of the bean.
... or inject prototype beans into other prototype beans.

@Singleton
class BuilderUser {

  final Provider<MyBuilder> builderProvider;

  @Inject
  BuilderUser(Provider<MyBuilder> builderProvider) {
    this.builderProvider = builderProvider;
  }

  MyBuilder createBuilder() {
    return builderProvider.get();
  }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions