package org.realityforge.tarrabah;

import org.apache.deltaspike.cdise.api.CdiContainer;
import org.apache.deltaspike.cdise.api.CdiContainerLoader;
import org.apache.deltaspike.cdise.api.ContextControl;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.realityforge.tarrabah.cdi.ext.pipeline.Pipeline;
import org.realityforge.tarrabah.cdi.ext.pipeline.PipelineScoped;

public class MainApp
{
  public static void main( final String[] args )
  {
    final CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();

    // Starting the application-context allows to use @PipelineScoped beans
    final ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext( PipelineScoped.class );
    contextControl.startContexts();

    Pipeline.activate( new Pipeline( "foo" ) );

    final SyslogUDPServer udpServer = BeanProvider.getContextualReference( SyslogUDPServer.class );
    final SyslogTCPServer tcpServer = BeanProvider.getContextualReference( SyslogTCPServer.class );

    System.err.println( "Active" );

    /*
    for ( int i = 0; i < 2; i++ )
    {
      try
      {
        Thread.sleep( 1000 );
      }
      catch ( final InterruptedException ie )
      {
        //ignored
      }
    }
    */

    contextControl.stopContext( PipelineScoped.class );
    Pipeline.deactivate();

    //contextControl.stopContexts();
    cdiContainer.shutdown();
    System.err.println( "Inactive" );
  }
}
@@ -29,16 +29,250 @@
 rabah;%0A%0A
+import javax.enterprise.context.ApplicationScoped;%0Aimport javax.enterprise.context.spi.CreationalContext;%0Aimport javax.enterprise.inject.spi.BeanManager;%0Aimport javax.enterprise.inject.spi.InjectionTarget;%0Aimport javax.inject.Inject;%0A
 import o
@@ -477,24 +477,31 @@
 rovider.Bean
+Manager
 Provider;%0Aim
@@ -648,16 +648,88 @@
 inApp%0A%7B%0A
+  static class Foo%0A  %7B%0A    @Inject%0A    private SyslogTCPServer _s;%0A%0A  %7D%0A
   public
@@ -1051,32 +1051,94 @@
 ol.startContext(
+ ApplicationScoped.class );%0A    //contextControl.startContext(
  PipelineScoped.
@@ -1187,24 +1187,30 @@
 );%0A%0A    
+final 
 Pipeline
 .activat
@@ -1205,18 +1205,14 @@
 line
-.activate(
+ foo =
  new
@@ -1233,117 +1233,512 @@
 o%22 )
- );%0A%0A    final SyslogUDPServer udpServer = BeanProvider.getContextualReference( SyslogUDPServer.class
+;%0A    Pipeline.activate( foo );%0A%0A    final BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();%0A    final CreationalContext%3CFoo%3E context = bm.createCreationalContext( null );%0A    final InjectionTarget%3CFoo%3E injectionTarget = bm.createInjectionTarget( bm.createAnnotatedType( Foo.class ) );%0A    final Foo instance = new Foo();%0A    //final Foo instance = injectionTarget.produce( context );%0A    injectionTarget.inject( instance, context );%0A    injectionTarget.postConstruct( instance
  );%0A    
 fina
@@ -1729,24 +1729,26 @@
 ance );%0A    
+//
 final Syslog
@@ -1878,14 +1878,9 @@
    /
-*%0A    
+/
 for 
@@ -1909,22 +1909,26 @@
 + )%0A    
+//
 %7B%0A    
+//
   try%0A  
@@ -1925,32 +1925,34 @@
 //  try%0A    
+//
   %7B%0A    
     Thread.s
@@ -1935,24 +1935,26 @@
   //  %7B%0A    
+//
     Thread.s
@@ -1971,24 +1971,26 @@
  );%0A    
+//
   %7D%0A    
   catch 
@@ -1981,16 +1981,18 @@
   %7D%0A    
+//
   catch 
@@ -2029,24 +2029,26 @@
 e )%0A    
+//
   %7B%0A    
     //ig
@@ -2039,16 +2039,18 @@
   %7B%0A    
+//
     //ig
@@ -2063,22 +2063,18 @@
     
-  %7D%0A  
+//
   %7D%0A    
 */%0A%0A
@@ -2073,10 +2073,11 @@
     
-*
 /
+/%7D
 %0A%0A  
@@ -2154,24 +2154,137 @@
 ctivate();%0A%0A
+    context.release();%0A    //injectionTarget.preDestroy( instance );%0A    //injectionTarget.dispose( instance );%0A%0A
     //contex

Rework example to try dynamic instantiation