File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { InstanceWrapper , InstanceWrapperArguments } from './instance-wrapper' ;
2
+ import { DependencyInterface } from '../internal-types' ;
3
+
4
+ export type FactoryInstanceWrapperArguments = InstanceWrapperArguments & {
5
+ factory : ( ) => any ;
6
+ dependencies : DependencyInterface [ ] ;
7
+ } ;
8
+
9
+ export class FactoryInstanceWrapper extends InstanceWrapper {
10
+ private readonly dependencies : DependencyInterface [ ] ;
11
+
12
+ private readonly factory : ( ...any ) => any ;
13
+
14
+ public constructor (
15
+ contextModule ,
16
+ {
17
+ dependencies,
18
+ factory,
19
+ ...instanceWrapperArguments
20
+ } : FactoryInstanceWrapperArguments ,
21
+ ) {
22
+ super ( contextModule , instanceWrapperArguments ) ;
23
+ this . factory = factory ;
24
+ this . dependencies = dependencies ;
25
+ }
26
+
27
+ public createInstance (
28
+ dependencyResolver : ( dependency : DependencyInterface ) => any ,
29
+ ) {
30
+ const resolvedDependencies = this . dependencies . map ( dependencyResolver ) ;
31
+ this . resolvedValue = this . factory ( ...resolvedDependencies ) ;
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments