1919use Doctrine \ORM \Tools \ToolEvents ;
2020use Patchlevel \EventSourcing \Attribute \Aggregate ;
2121use Patchlevel \EventSourcing \Attribute \Event ;
22+ use Patchlevel \EventSourcing \Attribute \Header ;
2223use Patchlevel \EventSourcing \Attribute \Processor ;
2324use Patchlevel \EventSourcing \Attribute \Projector ;
2425use Patchlevel \EventSourcing \Attribute \Subscriber ;
6162use Patchlevel \EventSourcing \Metadata \AggregateRoot \AggregateRootMetadataAwareMetadataFactory ;
6263use Patchlevel \EventSourcing \Metadata \AggregateRoot \AggregateRootMetadataFactory ;
6364use Patchlevel \EventSourcing \Metadata \AggregateRoot \AggregateRootRegistry ;
64- use Patchlevel \EventSourcing \Metadata \AggregateRoot \AttributeAggregateRootRegistryFactory ;
6565use Patchlevel \EventSourcing \Metadata \Event \AttributeEventMetadataFactory ;
66- use Patchlevel \EventSourcing \Metadata \Event \AttributeEventRegistryFactory ;
6766use Patchlevel \EventSourcing \Metadata \Event \EventMetadataFactory ;
6867use Patchlevel \EventSourcing \Metadata \Event \EventRegistry ;
6968use Patchlevel \EventSourcing \Metadata \Message \AttributeMessageHeaderRegistryFactory ;
153152use Symfony \Component \DependencyInjection \ContainerInterface ;
154153use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
155154use Symfony \Component \DependencyInjection \Extension \Extension ;
155+ use Symfony \Component \DependencyInjection \Parameter ;
156156use Symfony \Component \DependencyInjection \Reference ;
157157
158158use function class_exists ;
@@ -164,8 +164,6 @@ final class PatchlevelEventSourcingExtension extends Extension
164164 /** @param array<array-key, mixed> $configs */
165165 public function load (array $ configs , ContainerBuilder $ container ): void
166166 {
167- $ this ->removeNonServices ($ container );
168-
169167 $ configuration = new Configuration ();
170168
171169 /** @var Config $config */
@@ -185,7 +183,7 @@ public function load(array $configs, ContainerBuilder $container): void
185183 $ this ->configureConnection ($ config , $ container );
186184 $ this ->configureStore ($ config , $ container );
187185 $ this ->configureSnapshots ($ config , $ container );
188- $ this ->configureAggregates ($ config , $ container );
186+ $ this ->configureAggregates ($ container );
189187 $ this ->configureCommands ($ container );
190188 $ this ->configureProfiler ($ container );
191189 $ this ->configureClock ($ config , $ container );
@@ -202,11 +200,17 @@ public function load(array $configs, ContainerBuilder $container): void
202200 /** @param Config $config */
203201 private function configureSerializer (array $ config , ContainerBuilder $ container ): void
204202 {
205- $ container ->register (AttributeEventRegistryFactory::class);
203+ $ container ->registerAttributeForAutoconfiguration (
204+ Event::class,
205+ static function (ChildDefinition $ definition , Event $ attribute ): void {
206+ $ definition ->addResourceTag ('event_sourcing.event ' , ['name ' => $ attribute ->name ]);
207+ },
208+ );
209+
210+ $ container ->setParameter ('event_sourcing.events ' , []);
206211
207212 $ container ->register (EventRegistry::class)
208- ->setFactory ([new Reference (AttributeEventRegistryFactory::class), 'create ' ])
209- ->setArguments ([$ config ['events ' ]]);
213+ ->setArguments ([new Parameter ('event_sourcing.events ' )]);
210214
211215 $ container ->register (AttributeEventMetadataFactory::class);
212216 $ container ->setAlias (EventMetadataFactory::class, AttributeEventMetadataFactory::class);
@@ -224,12 +228,15 @@ private function configureSerializer(array $config, ContainerBuilder $container)
224228
225229 $ container ->setAlias (EventSerializer::class, DefaultEventSerializer::class);
226230
227- $ container ->register (AttributeMessageHeaderRegistryFactory::class);
228- $ container ->setAlias (MessageHeaderRegistryFactory::class, AttributeMessageHeaderRegistryFactory::class);
231+ $ container ->registerAttributeForAutoconfiguration (
232+ Header::class,
233+ static function (ChildDefinition $ definition , Header $ attribute ): void {
234+ $ definition ->addResourceTag ('event_sourcing.header ' , ['name ' => $ attribute ->name ]);
235+ },
236+ );
229237
230238 $ container ->register (MessageHeaderRegistry::class)
231- ->setFactory ([new Reference (MessageHeaderRegistryFactory::class), 'create ' ])
232- ->setArguments ([$ config ['headers ' ]]);
239+ ->setArguments ([new Parameter ('event_sourcing.headers ' )]);
233240
234241 $ container ->register (DefaultHeadersSerializer::class)
235242 ->setArguments ([
@@ -879,17 +886,22 @@ private function configureSnapshots(array $config, ContainerBuilder $container):
879886 $ container ->setAlias (SnapshotStore::class, DefaultSnapshotStore::class);
880887 }
881888
882- /** @param Config $config */
883- private function configureAggregates (array $ config , ContainerBuilder $ container ): void
889+ private function configureAggregates (ContainerBuilder $ container ): void
884890 {
891+ $ container ->registerAttributeForAutoconfiguration (
892+ Aggregate::class,
893+ static function (ChildDefinition $ definition , Aggregate $ attribute ): void {
894+ $ definition ->addResourceTag ('event_sourcing.aggregate ' , ['name ' => $ attribute ->name ]);
895+ },
896+ );
897+
885898 $ container ->register (AggregateRootMetadataAwareMetadataFactory::class);
886899 $ container ->setAlias (AggregateRootMetadataFactory::class, AggregateRootMetadataAwareMetadataFactory::class);
887900
888- $ container ->register (AttributeAggregateRootRegistryFactory::class );
901+ $ container ->setParameter ( ' event_sourcing.aggregates ' , [] );
889902
890903 $ container ->register (AggregateRootRegistry::class)
891- ->setFactory ([new Reference (AttributeAggregateRootRegistryFactory::class), 'create ' ])
892- ->setArguments ([$ config ['aggregates ' ]]);
904+ ->setArguments ([new Parameter ('event_sourcing.aggregates ' )]);
893905
894906 $ container ->register (DefaultRepositoryManager::class)
895907 ->setArguments ([
@@ -1221,26 +1233,4 @@ private function configureValueResolver(ContainerBuilder $container): void
12211233 $ container ->register (IdentifierValueResolver::class)
12221234 ->addTag ('controller.argument_value_resolver ' , ['priority ' => 200 ]);
12231235 }
1224-
1225- private function removeNonServices (ContainerBuilder $ container ): void
1226- {
1227- $ container ->registerAttributeForAutoconfiguration (
1228- Aggregate::class,
1229- static function (ChildDefinition $ definition ): void {
1230- $ definition ->setAbstract (true )->addTag (
1231- 'container.excluded ' ,
1232- ['source ' => sprintf ('with #[%s] attribute ' , Aggregate::class)],
1233- );
1234- },
1235- );
1236- $ container ->registerAttributeForAutoconfiguration (
1237- Event::class,
1238- static function (ChildDefinition $ definition ): void {
1239- $ definition ->setAbstract (true )->addTag (
1240- 'container.excluded ' ,
1241- ['source ' => sprintf ('with #[%s] attribute ' , Event::class)],
1242- );
1243- },
1244- );
1245- }
12461236}
0 commit comments