javax.enterprise.context.spi
Interface Context

All Known Implementing Classes:
AbstractScopeContext, ApplicationContext, ConversationContext, DependentContext, ErrorContext, RequestContext, SessionScopeImpl, SingletonScope, TransactionScope

public interface Context

Represents a bean scope, storing the bean instances available to the execution context, and corresponding to a @ScopeType. The Context is an SPI class, called by the inject Manager, but not normally by application code. Applications will call BeanManager.newInstance to create a new instance of a bean. Example contexts include @ApplicationScoped for singleton objects,


Method Summary
<T> T
get(Contextual<T> bean)
          Returns a instance of a bean, creating if the bean is not already available in the context.
<T> T
get(Contextual<T> bean, CreationalContext<T> creationalContext)
          Internal SPI method to create a new instance of a bean, when given a creational context.
 java.lang.Class<? extends java.lang.annotation.Annotation> getScope()
          Returns the @ScopeType corresponding to the current context.
 boolean isActive()
          Returns true if the scope is currently active.
 

Method Detail

getScope

java.lang.Class<? extends java.lang.annotation.Annotation> getScope()
Returns the @ScopeType corresponding to the current context.


isActive

boolean isActive()
Returns true if the scope is currently active.


get

<T> T get(Contextual<T> bean)
Returns a instance of a bean, creating if the bean is not already available in the context.

Parameters:
bean - the Bean type to be created
Returns:
an injected and initialized instance

get

<T> T get(Contextual<T> bean,
          CreationalContext<T> creationalContext)
Internal SPI method to create a new instance of a bean, when given a creational context. This method is needed to handle circular initialization of bean instances. If the bean already exists in the creationalContext, return the existing bean.

Parameters:
bean - the Bean type to be created
creationalContext - - temporary context used for managing circular references
Returns:
the bean instance