Skip to content

Instantly share code, notes, and snippets.

@pavolloffay
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavolloffay/2175416f816077135710 to your computer and use it in GitHub Desktop.
Save pavolloffay/2175416f816077135710 to your computer and use it in GitHub Desktop.
CDI EJB
CDI scopes
javax.enterprise.context.@RequestScoped
javax.enterprise.context.@SessionScoped
javax.enterprise.context.@ApplicationScoped
javax.enterprise.context.@ConversationScoped - If the user is doing multiple things at the same time, there are multiple conversations.
javax.enterprise.context.@Dependent - default scope. An instance of a dependent bean is never shared between different clients or different injection points. It is strictly a dependent object of some other object. They don't use proxy objects.
javax.inject.@Singleton - don’t have a proxy object. Clients hold a direct reference to its instance. Problems with serialization it's better to add @ApplicationScoped allowing the container to proxy the bean
@SessionScoped or @ConversationScoped must be serializable
Qualifiers
javax.enterprise.inject.@New - The built-in qualifier @New allows us to obtain a dependent object of a specified class. Even if the class is already declaren with different scope
Type safe dependency injection
javax.inject.@Inject -
javax.inject.@Qualifier - we need to implement this annotation
javax.enterprise.inject.@Alternative - by default is disabled, With this annotation we can solve ambiguous dependencies eg. by annotationg on possible bean.
javax.enterprise.inject.@Any Instance<HelloBean> beans - qualifier can be used when we have multiple implementations of one interface and we want to inject them all in another bean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment