Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cdi 457 #289

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions api/src/main/java/javax/enterprise/inject/spi/CDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package javax.enterprise.inject.spi;

import javax.enterprise.inject.Instance;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import javax.enterprise.inject.Instance;

/**
* Provides access to the current container.
Expand Down Expand Up @@ -107,9 +107,12 @@ public void close() {
*/
public abstract BeanManager getBeanManager();

// Helper methods

private static CDIProvider getCDIProvider() {
/**
*
* @return the {@link CDIProvider} retrieved by serviceloader or setted by user
*/
public static CDIProvider getCDIProvider() {
if (configuredProvider != null) {
return configuredProvider;
} else {
Expand All @@ -128,6 +131,8 @@ private static CDIProvider getCDIProvider() {
}
}

// Helper methods

private static void findAllProviders() {

ServiceLoader<CDIProvider> providerLoader;
Expand Down
17 changes: 17 additions & 0 deletions spec/src/main/asciidoc/core/scopescontexts.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@ Additionally, the container must ensure that:

Finally, the container is permitted to destroy any `@Dependent` scoped contextual instance at any time if the instance is no longer referenced by the application (excluding weak, soft and phantom references).

[[programmatic_dependent]]

==== Programmatic creation and destruction of objects with scope `@Dependent`

Dependent objects can be used as references within an `Instance` object. Creating an instance of a dependent object in this way creates one that is not bounded to the creational context of the injection point. This true also when using the `CDI` utility class. Since the container may not be able to track these instances against a context, they must be destroyed after use.

```
@Inject
Instance<MyDependentClass> instance;

MyDependentClass object = instance.get();

// do work with that instance

instance.destroy(object);
```


[[contextual_instances_and_references]]

Expand Down