33namespace ApiClients \Foundation ;
44
55use ApiClients \Foundation \Events \CommandLocatorEvent ;
6+ use ApiClients \Foundation \Events \ServiceLocatorEvent ;
67use ApiClients \Foundation \Hydrator \Factory as HydratorFactory ;
78use ApiClients \Foundation \Hydrator \Hydrator ;
89use ApiClients \Foundation \Transport \Client as TransportClient ;
910use ApiClients \Foundation \Transport \Factory as TransportFactory ;
1011use ApiClients \Tools \CommandBus \CommandBus ;
12+ use Generator ;
1113use Interop \Container \ContainerInterface ;
1214use League \Container \Container ;
1315use League \Container \ReflectionContainer ;
@@ -34,6 +36,12 @@ public static function create(
3436 $ container ->share (CommandBus::class, function () use ($ container ) {
3537 return self ::createCommandBus ($ container );
3638 });
39+ array_map (
40+ [$ container , 'share ' ],
41+ iterator_to_array (
42+ self ::locateServices ($ container ->get (EmitterInterface::class))
43+ )
44+ );
3745
3846 return new Client (
3947 $ container
@@ -78,6 +86,11 @@ private static function mapCommandsToHandlers(EmitterInterface $emitter): array
7886 return $ emitter ->emit (CommandLocatorEvent::create ())->getMap ();
7987 }
8088
89+ private static function locateServices (EmitterInterface $ emitter ): Generator
90+ {
91+ return $ emitter ->emit (ServiceLocatorEvent::create ())->getMap ();
92+ }
93+
8194 private static function createTransport (
8295 ContainerInterface $ container ,
8396 LoopInterface $ loop = null ,
0 commit comments