@@ -26,6 +26,8 @@ final class DBeanScopeBuilder implements BeanScopeBuilder.ForTesting {
26
26
@ SuppressWarnings ("rawtypes" )
27
27
private final List <EnrichBean > enrichBeans = new ArrayList <>();
28
28
private final Set <Module > includeModules = new LinkedHashSet <>();
29
+ private final List <Runnable > postConstructList = new ArrayList <>();
30
+ private final List <AutoCloseable > preDestroyList = new ArrayList <>();
29
31
private BeanScope parent ;
30
32
private boolean parentOverride = true ;
31
33
private boolean shutdownHook ;
@@ -106,6 +108,18 @@ public <D> BeanScopeBuilder provideDefault(String name, Type type, Supplier<D> s
106
108
return this ;
107
109
}
108
110
111
+ @ Override
112
+ public BeanScopeBuilder addPostConstructHooks (Runnable ... postConstructRunnable ) {
113
+ Collections .addAll (this .postConstructList , postConstructRunnable );
114
+ return this ;
115
+ }
116
+
117
+ @ Override
118
+ public BeanScopeBuilder addPreDestroyHooks (AutoCloseable ... closables ) {
119
+ Collections .addAll (this .preDestroyList , closables );
120
+ return this ;
121
+ }
122
+
109
123
@ Override
110
124
public BeanScopeBuilder classLoader (ClassLoader classLoader ) {
111
125
this .classLoader = classLoader ;
@@ -130,6 +144,7 @@ public BeanScopeBuilder.ForTesting mock(Class<?> type) {
130
144
return mock (type , null , null );
131
145
}
132
146
147
+ @ Override
133
148
public BeanScopeBuilder .ForTesting mock (Class <?> type , String name ) {
134
149
return mock (type , name , null );
135
150
}
@@ -149,7 +164,8 @@ public BeanScopeBuilder.ForTesting spy(Class<?> type) {
149
164
return spy (type , null , null );
150
165
}
151
166
152
- public BeanScopeBuilder .ForTesting spy (Class <?> type , String name ) {
167
+ @ Override
168
+ public BeanScopeBuilder .ForTesting spy (Class <?> type , String name ) {
153
169
return spy (type , name , null );
154
170
}
155
171
@@ -206,6 +222,9 @@ public BeanScope build() {
206
222
for (Module factory : factoryOrder .factories ()) {
207
223
factory .build (builder );
208
224
}
225
+
226
+ postConstructList .forEach (builder ::addPostConstruct );
227
+ preDestroyList .forEach (builder ::addPreDestroy );
209
228
return builder .build (shutdownHook , start );
210
229
}
211
230
0 commit comments