Skip to content

Commit cbadf9d

Browse files
committed
Fix javadoc, add request scope example, remove BeanLifecycle
1 parent 5c5f11b commit cbadf9d

File tree

10 files changed

+74
-37
lines changed

10 files changed

+74
-37
lines changed

inject/src/main/java/io/avaje/inject/ApplicationScope.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.util.List;
44

55
/**
6-
* Provides a global system wide BeanScope that contains all the bean contexts in the classpath.
6+
* Provides a global system wide BeanScope that contains all the beans.
77
* <p>
8-
* This will automatically get all the bean contexts and wire them all as necessary. It will use
8+
* This will automatically get all the beans and wire them all as necessary. It will use
99
* a shutdown hook to fire any <code>@PreDestroy</code> methods on beans.
1010
* </p>
1111
*
@@ -140,6 +140,35 @@ public static List<Object> listByAnnotation(Class<?> annotation) {
140140
/**
141141
* Start building a RequestScope.
142142
*
143+
* <pre>{@code
144+
*
145+
* try (RequestScope requestScope = ApplicationScope.newRequestScope()
146+
* // supply some instances
147+
* .withBean(HttpRequest.class, request)
148+
* .withBean(HttpResponse.class, response)
149+
* .build()) {
150+
*
151+
* MyController controller = requestScope.get(MyController.class);
152+
* controller.process();
153+
*
154+
* }
155+
*
156+
* ...
157+
*
158+
* // define request scoped beans
159+
* @Request
160+
* MyController {
161+
*
162+
* // can depend on supplied instances, singletons and other request scope beans
163+
* @Inject
164+
* MyController(HttpRequest request, HttpResponse response, MyService myService) {
165+
* ...
166+
* }
167+
*
168+
* }
169+
*
170+
* }</pre>
171+
*
143172
* @return The request scope builder
144173
*/
145174
public static RequestScopeBuilder newRequestScope() {

inject/src/main/java/io/avaje/inject/BeanScope.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public interface BeanScope extends Closeable {
4646

4747
/**
48-
* Build a bean context with options for shutdown hook and supplying test doubles.
48+
* Build a bean scope with options for shutdown hook and supplying test doubles.
4949
* <p>
5050
* We would choose to use BeanScopeBuilder in test code (for component testing)
5151
* as it gives us the ability to inject test doubles, mocks, spy's etc.
@@ -70,7 +70,6 @@ public interface BeanScope extends Closeable {
7070
* assertThat(...
7171
* }
7272
* }
73-
*
7473
* }</pre>
7574
*/
7675
static BeanScopeBuilder newBuilder() {
@@ -80,6 +79,34 @@ static BeanScopeBuilder newBuilder() {
8079
/**
8180
* Create a RequestScope via builder where we provide extra instances
8281
* that can be used/included in wiring request scoped beans.
82+
*
83+
* <pre>{@code
84+
*
85+
* try (RequestScope requestScope = beanScope.newRequestScope()
86+
* // supply some instances
87+
* .withBean(HttpRequest.class, request)
88+
* .withBean(HttpResponse.class, response)
89+
* .build()) {
90+
*
91+
* MyController controller = requestScope.get(MyController.class);
92+
* controller.process();
93+
* }
94+
*
95+
* ...
96+
*
97+
* // define request scoped beans
98+
* @Request
99+
* MyController {
100+
*
101+
* // can depend on supplied instances, singletons and other request scope beans
102+
* @Inject
103+
* MyController(HttpRequest request, HttpResponse response, MyService myService) {
104+
* ...
105+
* }
106+
*
107+
* }
108+
*
109+
* }</pre>
83110
*/
84111
RequestScopeBuilder newRequestScope();
85112

inject/src/main/java/io/avaje/inject/BeanScopeBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.function.Consumer;
44

55
/**
6-
* Build a bean context with options for shutdown hook and supplying test doubles.
6+
* Build a bean scope with options for shutdown hook and supplying test doubles.
77
* <p>
88
* We would choose to use BeanScopeBuilder in test code (for component testing) as it gives us
99
* the ability to inject test doubles, mocks, spy's etc.
@@ -34,7 +34,7 @@
3434
public interface BeanScopeBuilder {
3535

3636
/**
37-
* Create the bean context without registering a shutdown hook.
37+
* Create the bean scope without registering a shutdown hook.
3838
* <p>
3939
* The expectation is that the BeanScopeBuilder is closed via code or via using
4040
* try with resources.
@@ -286,7 +286,7 @@ public interface BeanScopeBuilder {
286286
<D> BeanScopeBuilder withSpy(Class<D> type, Consumer<D> consumer);
287287

288288
/**
289-
* Build and return the bean context.
289+
* Build and return the bean scope.
290290
*
291291
* @return The BeanScope
292292
*/

inject/src/main/java/io/avaje/inject/ContextModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package io.avaje.inject;
22

33
/**
4-
* Used to explicitly name a bean context and optionally specify if it depends on other bean contexts.
4+
* Used to explicitly name a bean scope and optionally specify if it depends on other bean scopes.
55
* <p>
66
* If this annotation is not present then the name will be derived as the "top level package name"
77
* e.g. "org.example.featuretoggle"
88
* </p>
99
*
1010
* <p>
11-
* Typically there is a single bean context per Jar (module). In that sense the name is the "module name" and
11+
* Typically there is a single bean scope per Jar (module). In that sense the name is the "module name" and
1212
* the dependsOn specifies the names of modules that this depends on (provide beans that are used to wire this module).
1313
* </p>
1414
*

inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99

10-
import java.lang.annotation.Annotation;
1110
import java.util.*;
12-
import java.util.concurrent.locks.ReentrantLock;
1311
import java.util.function.Consumer;
1412

1513
/**
16-
* Build a bean context with options for shutdown hook and supplying test doubles.
14+
* Build a bean scope with options for shutdown hook and supplying test doubles.
1715
*/
1816
class DBeanScopeBuilder implements BeanScopeBuilder {
1917

inject/src/main/java/io/avaje/inject/SystemContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/**
66
* Deprecated - migrate to ApplicationScope.
77
* <p>
8-
* Provides a global system wide BeanScope that contains all the bean contexts in the classpath.
8+
* Provides a global system wide BeanScope that contains all the beans.
99
* <p>
10-
* This will automatically get all the bean contexts and wire them all as necessary. It will use
10+
* This will automatically get all the beans and wire them all as necessary. It will use
1111
* a shutdown hook to fire any <code>@PreDestroy</code> methods on beans.
1212
* </p>
1313
*

inject/src/main/java/io/avaje/inject/spi/BeanContextFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.avaje.inject.spi;
22

33
/**
4-
* This is the service loader interface defining the bean contexts that can be created.
4+
* This is the service loader interface defining the bean scope.
55
*/
66
public interface BeanContextFactory {
77

88
/**
9-
* Return the name of the bean context (module) this will create.
9+
* Return the name of the bean scope (module) this will create.
1010
*/
1111
String getName();
1212

@@ -16,7 +16,7 @@ public interface BeanContextFactory {
1616
String[] getProvides();
1717

1818
/**
19-
* Return the names of bean contexts (modules) that this is dependent on (they need to be built before this one).
19+
* Return the names of bean scopes (modules) that this is dependent on (they need to be built before this one).
2020
*/
2121
String[] getDependsOn();
2222

inject/src/main/java/io/avaje/inject/spi/BeanLifecycle.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

inject/src/main/java/io/avaje/inject/spi/Builder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.function.Consumer;
1212

1313
/**
14-
* Mutable builder object used when building a bean context.
14+
* Mutable builder object used when building a bean scope.
1515
*/
1616
public interface Builder {
1717

@@ -161,7 +161,7 @@ static Builder newBuilder(List<SuppliedBean> suppliedBeans, List<EnrichBean> enr
161161
<T> T enrich(T bean, Class<?>[] types);
162162

163163
/**
164-
* Build and return the bean context.
164+
* Build and return the bean scope.
165165
*/
166166
BeanScope build(boolean withShutdownHook);
167167
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* Building bean context objects expected to only be used by generated code.
2+
* Building bean scope objects expected to only be used by generated code.
33
*/
44
package io.avaje.inject.spi;

0 commit comments

Comments
 (0)