File tree Expand file tree Collapse file tree 2 files changed +21
-48
lines changed
Expand file tree Collapse file tree 2 files changed +21
-48
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 88
99namespace DevNet \Common \Dependency ;
1010
11+ use DevNet \System \Activator ;
12+
1113class ServiceProvider implements IServiceProvider
1214{
1315 private array $ instanceServices = [];
@@ -50,7 +52,25 @@ public function getService(string $serviceType): ?object
5052 }
5153 }
5254
53- $ instance = Activator::CreateInstance ($ serviceDescriptor ->ImplementationType , $ this );
55+ $ instance = Activator::CreateInstance ($ serviceDescriptor ->ImplementationType , [$ this ],
56+ function (array $ args , array $ params ) {
57+ $ provider = $ args [0 ];
58+ $ args = [];
59+ foreach ($ params as $ parameter ) {
60+ $ parameterType = '' ;
61+ if ($ parameter ->getType ()) {
62+ $ parameterType = $ parameter ->getType ()->getName ();
63+ }
64+
65+ if (!$ provider ->contains ($ parameterType )) {
66+ break ;
67+ }
68+
69+ $ args [] = $ provider ->getService ($ parameterType );
70+ }
71+
72+ return $ args ;
73+ });
5474 $ this ->instanceServices [$ serviceType ] = $ instance ;
5575 return $ instance ;
5676 }
You can’t perform that action at this time.
0 commit comments