I am trying to find an analog to Seam 2 Factory paradigm in CDI. I have used factory annotated methods and factory definitions in components.xml extensively in the past projects. Generally I use them as a sort of Cache and when I know the cache is stale I remove the component from the context and the factory method will run again the next time the Factory is required.
For instance, in a production application we have lists of available medications that gets updated yearly. This list is used extensively in the application so we cache it in memory using a Factory annotated Application scoped method.
@Factory(scope = ScopeType.APPLICATION, autoCreate = true, value = "meds")
public List<Medications> buildMedsList(){
///....Do work to parse, index and build list
}
Once the new list is uploaded we simply remove the "meds" Object from the Application Context and then access it to be sure it is cached
Contexts.getApplicationContext().remove("meds");
Component.getInstance("meds");
There are a LOT of lists/objects that behave similarly. Supplying everything from SelectItem lists for radio button groups to dialog message text and end user license text. All of which have lifetimes that are VERY long but are required to be update-able without restarting the application server. I also use this same technique with some session scoped variables which have an unknown lifespan (May need to be refreshed dependant on user interactions).
So far I see the CDI Producer which is very similar to a Factory but I can't see how it can be used in a similar way to how I was using the Seam 2 Equivalent without building a wrapper class for each factory. Also I don't see a way to remove things from the CDI contexts. Therefore, I can't have these arbitrarily long lived objects without some special scope that I invent.
I am totally new to CDI so I am probably missing some technique.