Posts

Showing posts with the label factory

Inject new objects in for loop with CDI (Weld)

Image
Clash Royale CLAN TAG #URR8PPP Inject new objects in for loop with CDI (Weld) I want to introduce CDI to existing project. Currently we are creating new objects inside for loop like Context context; for(String string : strings) { context = new Context(); // do some operations with string. // set outcomes of above operation in context. } Now if I am injecting Context as Context @Inject Context context; I'm getting same instance every time. I'm wondering if there is any way available in CDI to create new Context inside loop? Context Why would you need that? You are trying to abuse the dependency injection mechanism. – Adrian Mitev Oct 3 '14 at 19:35 Hi Adrian, do you think it would be a design approach. Although its a use case requirement, but before opting for it, I would definitely like ...