3 Replies Latest reply on Aug 27, 2012 3:13 PM by sboscarine

    Can I write a method producer method without knowing the type until runtime?  (framework for making @Produces on annotated types)


      Hello All,

      I'd like to write a configuration framework so that a user can define a bean, add a special annotation I'd define, and my factory classes would inject properties into the bean and make it available to CDI. 


      Our problem is that we have an application that gets values based on keys, but has to query multiple heterogenous sources, so we can't use Hibernate or anything like that.


      I am thinking of having the user write a class like:


      public class DataStoreSettings{
           int numberOfThreads;
           File rootFolder;


      My engine would:

      1. (already written) Find all instances annotated with @Config
      2. (already written) Look up property associated with key in annotation info from database and other sources
      3. (already written) Inject value into instance of bean
      4. (needed) Exposed bean to CDI (not sure the correct term, but the equivalent of "@Produces DataStoreSettings")
      5. Consumer would then just write "@Inject DataStoreSettings settings" in their consuming code and get the information from our dozen configuration sources.


      Where should I start to learn how to make a generic factory that produces beans based on what it finds on annotation scanning?