17
17
import org .int4 .dirk .api .instantiation .UnsatisfiedResolutionException ;
18
18
import org .int4 .dirk .api .scope .ScopeException ;
19
19
import org .int4 .dirk .api .scope .ScopeNotActiveException ;
20
- import org .int4 .dirk .core .RootInstantiationContextFactory . RootInstantiationContext ;
20
+ import org .int4 .dirk .core .RootInstanceFactory . RootInstance ;
21
21
import org .int4 .dirk .core .definition .Binding ;
22
22
import org .int4 .dirk .core .definition .ExtendedScopeResolver ;
23
23
import org .int4 .dirk .core .definition .Injectable ;
30
30
import org .int4 .dirk .spi .config .AnnotationStrategy ;
31
31
import org .int4 .dirk .spi .config .ProxyStrategy ;
32
32
import org .int4 .dirk .spi .instantiation .InjectionTargetExtension ;
33
+ import org .int4 .dirk .spi .instantiation .Instance ;
33
34
import org .int4 .dirk .spi .instantiation .InstanceProvider ;
34
- import org .int4 .dirk .spi .instantiation .InstantiationContext ;
35
35
import org .int4 .dirk .spi .instantiation .Resolution ;
36
36
import org .int4 .dirk .spi .scope .CreationalContext ;
37
37
import org .int4 .dirk .spi .scope .ScopeResolver ;
38
38
import org .int4 .dirk .util .Types ;
39
39
40
40
/**
41
- * Factory for {@link InstantiationContext }s.
41
+ * Factory for {@link Instance }s.
42
42
*/
43
- class InstantiationContextFactory {
44
- private static final Logger LOGGER = Logger .getLogger (InstantiationContextFactory .class .getName ());
43
+ class InstanceFactory {
44
+ private static final Logger LOGGER = Logger .getLogger (InstanceFactory .class .getName ());
45
45
private static final ExtendedCreationalContext <?> NULL_CONTEXT = new FixedCreationalContext <>(null );
46
46
47
47
private static boolean strictOrder ;
48
48
49
49
private final ProxyStrategy proxyStrategy ;
50
50
private final InjectionTargetExtensionStore injectionTargetExtensionStore ;
51
- private final RootInstantiationContextFactory rootInstantiationContextFactory ;
51
+ private final RootInstanceFactory rootInstanceFactory ;
52
52
private final ThreadLocal <Deque <ExtendedCreationalContext <?>>> stack = ThreadLocal .withInitial (ArrayDeque ::new );
53
53
54
54
/**
@@ -58,14 +58,14 @@ class InstantiationContextFactory {
58
58
* @param proxyStrategy a {@link ProxyStrategy}, cannot be {@code null}
59
59
* @param injectionTargetExtensionStore an {@link InjectionTargetExtensionStore}, cannot be {@code null}
60
60
*/
61
- InstantiationContextFactory (AnnotationStrategy annotationStrategy , ProxyStrategy proxyStrategy , InjectionTargetExtensionStore injectionTargetExtensionStore ) {
61
+ InstanceFactory (AnnotationStrategy annotationStrategy , ProxyStrategy proxyStrategy , InjectionTargetExtensionStore injectionTargetExtensionStore ) {
62
62
this .proxyStrategy = Objects .requireNonNull (proxyStrategy , "proxyStrategy" );
63
63
this .injectionTargetExtensionStore = Objects .requireNonNull (injectionTargetExtensionStore , "injectionTargetExtensionStore" );
64
- this .rootInstantiationContextFactory = new RootInstantiationContextFactory (annotationStrategy );
64
+ this .rootInstanceFactory = new RootInstanceFactory (annotationStrategy );
65
65
}
66
66
67
- <T > InstantiationContext <T > createContext (Resolver <Injectable <?>> resolver , Key key , boolean optional ) {
68
- return rootInstantiationContextFactory .create (resolver , createInstantiatorInternal (key , optional , null ));
67
+ <T > Instance <T > createInstance (Resolver <Injectable <?>> resolver , Key key , boolean optional ) {
68
+ return rootInstanceFactory .create (resolver , createInstantiatorInternal (key , optional , null ));
69
69
}
70
70
71
71
<T > Instantiator <T > createInstantiator (Key key , boolean optional , Annotation parentScope ) {
@@ -156,13 +156,13 @@ public ExtendedCreationalContext<T> create(Resolver<Injectable<?>> resolver) thr
156
156
return castContext ;
157
157
}
158
158
159
- RootInstantiationContext <E , ?> instantiationContext = rootInstantiationContextFactory .create (resolver , elementInstantiator );
160
- InjectionTargetExtensionCreationalContext <T , E > creationalContext = new InjectionTargetExtensionCreationalContext <>(stack .get ().isEmpty () ? null : stack .get ().getLast (), resolution == Resolution .LAZY ? instantiationContext : null );
159
+ RootInstance <E , ?> instance = rootInstanceFactory .create (resolver , elementInstantiator );
160
+ InjectionTargetExtensionCreationalContext <T , E > creationalContext = new InjectionTargetExtensionCreationalContext <>(stack .get ().isEmpty () ? null : stack .get ().getLast (), resolution == Resolution .LAZY ? instance : null );
161
161
162
162
open (resolution == Resolution .LAZY ? NULL_CONTEXT : creationalContext );
163
163
164
164
try {
165
- creationalContext .initialize (instanceProvider .getInstance (instantiationContext ), resolution == Resolution .LAZY );
165
+ creationalContext .initialize (instanceProvider .getInstance (instance ), resolution == Resolution .LAZY );
166
166
167
167
return creationalContext ;
168
168
}
@@ -350,16 +350,16 @@ public void attach(ExtendedCreationalContext<?> creationalContext) {
350
350
351
351
private static final class InjectionTargetExtensionCreationalContext <T , E > implements ExtendedCreationalContext <T > {
352
352
private final ExtendedCreationalContext <?> parent ;
353
- private final RootInstantiationContext <E , ?> instantiationContext ;
353
+ private final RootInstance <E , ?> rootInstance ;
354
354
355
355
private T instance ;
356
356
private boolean needsDestroy ;
357
357
private boolean initialized ;
358
358
private List <CreationalContext <?>> children ;
359
359
360
- InjectionTargetExtensionCreationalContext (ExtendedCreationalContext <?> parent , RootInstantiationContext <E , ?> context ) {
360
+ InjectionTargetExtensionCreationalContext (ExtendedCreationalContext <?> parent , RootInstance <E , ?> rootInstance ) {
361
361
this .parent = parent ;
362
- this .instantiationContext = context ;
362
+ this .rootInstance = rootInstance ;
363
363
}
364
364
365
365
void initialize (T instance , boolean needsDestroy ) {
@@ -395,8 +395,8 @@ public final void attach(ExtendedCreationalContext<?> child) {
395
395
396
396
@ Override
397
397
public void release () {
398
- if (instantiationContext != null ) {
399
- instantiationContext .release ();
398
+ if (rootInstance != null ) {
399
+ rootInstance .release ();
400
400
}
401
401
402
402
if (children != null ) {
@@ -443,7 +443,7 @@ public boolean needsDestroy() {
443
443
*
444
444
* <p>A {@code CreationalContext} is created whenever an {@link Injectable} is obtained from
445
445
* a {@link ScopeResolver}. If the resolver decides to create a new instance, it will
446
- * call recursively into a {@link InstantiationContext }.
446
+ * call recursively into a {@link Instance }.
447
447
*/
448
448
private class LazyCreationalContext <T > implements ExtendedCreationalContext <T > {
449
449
private final ExtendedCreationalContext <?> parent ;
0 commit comments