Two "Singletons" of the same class
Hypothetically is it possible to have CDI inject exactly 2 different instances of the same class throughout my code? Two singletons of one class so to speak? And if yes, what would the annotations look like? Producing two different @Named instances with @Produces methods? Here is what I came up with: @Singleton public final class StartupBean { @Inject StartupBean(SomeManager someManager) { // nothing happening here } @Produces @Named("fooObject") public MyImplementation produceFooObject() { return new MyImplementation(); } @Produces @Named("barObject") public MyImplementation produceBarObject(
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.