You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ra...@apache.org on 2014/08/18 23:02:09 UTC

svn commit: r1618735 - /deltaspike/site/trunk/content/core.mdtext

Author: rafabene
Date: Mon Aug 18 21:02:09 2014
New Revision: 1618735

URL: http://svn.apache.org/r1618735
Log:
DELTASPIKE-640 - give some hints how to implement custom scopes

Modified:
    deltaspike/site/trunk/content/core.mdtext

Modified: deltaspike/site/trunk/content/core.mdtext
URL: http://svn.apache.org/viewvc/deltaspike/site/trunk/content/core.mdtext?rev=1618735&r1=1618734&r2=1618735&view=diff
==============================================================================
--- deltaspike/site/trunk/content/core.mdtext (original)
+++ deltaspike/site/trunk/content/core.mdtext Mon Aug 18 21:02:09 2014
@@ -820,67 +820,67 @@ If you want to create a custom CDI scope
 
 First, create an Annotation with annotated with @javax.inject.Scope; Example:
 
-      :::java
-      @Scope
-      @Retention(RetentionPolicy.RUNTIME)
-      @Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
-      public @interface ACustomScope {}
+    :::java
+    @Scope
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
+    public @interface ACustomScope {}
     
 Second, create an Extension to add the scope and a context for it. Example:
 
-      :::java    
-      public class ACustomScopeExtension implements Extension, Serializable {
-	
-      	public void addACustomScope(@Observes final BeforeBeanDiscovery event) {
-      		event.addScope(ACustomScope.class, true, false);
-      	}
-
-      	public void registerACustomScopeContext(@Observes final AfterBeanDiscovery event) {
-      		event.addContext(new ACustomScopeContext());
-      	}
-      }
+    :::java    
+    public class ACustomScopeExtension implements Extension, Serializable {
+
+    	public void addACustomScope(@Observes final BeforeBeanDiscovery event) {
+    		event.addScope(ACustomScope.class, true, false);
+    	}
+
+    	public void registerACustomScopeContext(@Observes final AfterBeanDiscovery event) {
+    		event.addContext(new ACustomScopeContext());
+    	}
+    }
 
 Implement a javax.enterprise.context.spi.Context interface to hold the javax.enterprise.inject.spi.Bean instances according to your needs
 
-      :::java
-      public class ACustomScopeContext implements Context, Serializable {
+    :::java
+    public class ACustomScopeContext implements Context, Serializable {
 
-        // Get the scope type of the context object.
-      	public Class<? extends Annotation> getScope() {
-      		return ACustomScope.class;
-      	}
-
-      	// Return an existing instance of certain contextual type or create a new instance by calling
-      	// javax.enterprise.context.spi.Contextual.create(CreationalContext) and return the new instance.
-      	public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
-      		Bean bean = (Bean) contextual;
-      		// you can store the bean somewhere
-      		if (somewhere.containsKey(bean.getName())) {
-      			return (T) somewhere.get(bean.getName());
-      		} else {
-      			T t = (T) bean.create(creationalContext);
-      			somewhere.put(bean.getName(), t);
-      			return t;
-      		}
-      	}
-
-      	// Return an existing instance of a certain contextual type or a null value.
-      	public <T> T get(Contextual<T> contextual) {
-      		Bean bean = (Bean) contextual;
-      		// you can store the bean somewhere
-      		if (somewhere.containsKey(bean.getName())) {
-      			return (T) somewhere.get(bean.getName());
-      		} else {
-      			return null;
-      		}
-      	}
-      
-        // Determines if the context object is active.
-      	public boolean isActive() {
-      		return true;
-      	}
+      // Get the scope type of the context object.
+    	public Class<? extends Annotation> getScope() {
+    		return ACustomScope.class;
+    	}
+
+    	// Return an existing instance of certain contextual type or create a new instance by calling
+    	// javax.enterprise.context.spi.Contextual.create(CreationalContext) and return the new instance.
+    	public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
+    		Bean bean = (Bean) contextual;
+    		// you can store the bean somewhere
+    		if (somewhere.containsKey(bean.getName())) {
+    			return (T) somewhere.get(bean.getName());
+    		} else {
+    			T t = (T) bean.create(creationalContext);
+    			somewhere.put(bean.getName(), t);
+    			return t;
+    		}
+    	}
+
+    	// Return an existing instance of a certain contextual type or a null value.
+    	public <T> T get(Contextual<T> contextual) {
+    		Bean bean = (Bean) contextual;
+    		// you can store the bean somewhere
+    		if (somewhere.containsKey(bean.getName())) {
+    			return (T) somewhere.get(bean.getName());
+    		} else {
+    			return null;
+    		}
+    	}
+    
+      // Determines if the context object is active.
+    	public boolean isActive() {
+    		return true;
+    	}
 
-      }
+    }
 
 ## Deactivatable