File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed
packages/protocol/src/protocol Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -181,14 +181,27 @@ export class Protocol<
181
181
}
182
182
} ) ;
183
183
184
- const runtime : ModuleContainer < any > = this . container . resolve ( "Runtime" ) ;
185
- runtime . moduleNames . forEach ( ( runtimeModuleName ) => {
186
- this . container . register ( runtimeModuleName , {
187
- useFactory : ( dependencyContainer ) => {
188
- return runtime . resolve ( runtimeModuleName ) ;
189
- } ,
184
+ // Cross-register all runtime modules to the protocol container for easier
185
+ // access of runtime modules inside protocol hooks
186
+ if ( this . container . isRegistered ( "Runtime" , true ) ) {
187
+ const runtimeContainer : ModuleContainer < any > =
188
+ this . container . resolve ( "Runtime" ) ;
189
+
190
+ runtimeContainer . moduleNames . forEach ( ( runtimeModuleName ) => {
191
+ this . container . register ( runtimeModuleName , {
192
+ useFactory : ( dependencyContainer ) => {
193
+ // Prevents creation of closure
194
+ const runtime : ModuleContainer < any > =
195
+ dependencyContainer . resolve ( "Runtime" ) ;
196
+ return runtime . resolve ( runtimeModuleName ) ;
197
+ } ,
198
+ } ) ;
190
199
} ) ;
191
- } ) ;
200
+ } else {
201
+ log . warn (
202
+ "Couldn't resolve Runtime reference in Protocol, resolving RuntimeModules in hooks won't be available"
203
+ ) ;
204
+ }
192
205
}
193
206
194
207
public async start ( ) {
You can’t perform that action at this time.
0 commit comments