[windup-dev] CDI question - producer

Ondrej Zizka ozizka at redhat.com
Tue Sep 9 03:08:44 EDT 2014


Hi, with this

----------------------------------------------------------------
@Singleton
public class GraphContextFactoryImpl implements GraphContextFactory
{
     @Inject
     private GraphApiCompositeClassLoaderProvider 
graphApiCompositeClassLoaderProvider;

     @Inject
     private Imported<Service<? extends VertexFrame>> graphServices;

     @Inject
     private GraphTypeRegistry graphTypeRegistry;

     private GraphContext graphContext;
----------------------------------------------------------------


is there a difference between the following two?
Basically I just moved the core of the creation.
A is master, B is my branch, results in the GraphContext being created 
at each @Inject.
I think I am missing something here.

Thanks, Ondra


---A-------------------------------------------------------------
    @Override
     public GraphContext create(){
         return produceGraphContext();
     }

     @Produces  @ApplicationScoped
     public GraphContext produceGraphContext(){
          if (this.graphContext == null){
             this.graphContext = new GraphContextImpl(graphServices, 
this.graphTypeRegistry, this.graphApiCompositeClassLoaderProvider);
         }
         return graphContext;
     }

----B-----------------------------------------------------------

     @Override
     public GraphContext create()    {
         return new GraphContextImpl(
             this.graphServices,
             this.graphTypeRegistry,
             this.graphApiCompositeClassLoaderProvider);
     }

     @Produces  @ApplicationScoped
     public GraphContext produceGraphContext(){
         if (this.graphContext == null) {
             this.graphContext = this.create();
         }
         return graphContext;
     }



More information about the windup-dev mailing list