@@ -303,6 +303,11 @@ final class Profile extends BasicAggregateRoot
303303 }
304304}
305305```
306+ !!! tip
307+
308+ You don't necessarily need to define multiple `Apply` attributes with the event class
309+ if you define the event types in the method using a union type.
310+
306311## Suppress missing apply methods
307312
308313Sometimes you have events that do not change the state of the aggregate itself,
@@ -358,6 +363,36 @@ final class Profile extends BasicAggregateRoot
358363
359364 When all events are suppressed, debugging becomes more difficult if you forget an apply method.
360365
366+ ## Shared apply context
367+
368+ When using [ micro-aggregates] ( ./aggregate.md#micro-aggregates ) ,
369+ you often need to suppress many missing applies for events that are handled by other aggregates.
370+ Using ` SharedApplyContext ` allows you to specify that multiple aggregates share the apply context.
371+ This way, missing applies are only reported if none of the aggregates handle them.
372+
373+ ``` php
374+ use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
375+ use Patchlevel\EventSourcing\Attribute\Aggregate;
376+ use Patchlevel\EventSourcing\Attribute\SharedApplyContext;
377+ use Patchlevel\EventSourcing\Attribute\Stream;
378+
379+ #[Aggregate('profile')]
380+ #[SharedApplyContext([PersonalInformation::class])]
381+ final class Profile extends BasicAggregateRoot
382+ {
383+ }
384+
385+ #[Aggregate('personal_information')]
386+ #[Stream(Profile::class)]
387+ #[SharedApplyContext([Profile::class])]
388+ final class PersonalInformation extends BasicAggregateRoot
389+ {
390+ }
391+ ```
392+ !!! warning
393+
394+ You need to define the `SharedApplyContext` attribute on all aggregates that share the apply context.
395+
361396## Stream Name
362397
363398!!! warning
@@ -675,8 +710,10 @@ use Patchlevel\EventSourcing\Aggregate\Uuid;
675710use Patchlevel\EventSourcing\Attribute\Aggregate;
676711use Patchlevel\EventSourcing\Attribute\Apply;
677712use Patchlevel\EventSourcing\Attribute\Id;
713+ use Patchlevel\EventSourcing\Attribute\SharedApplyContext;
678714
679715#[Aggregate('order')]
716+ #[SharedApplyContext([Shipping::class])]
680717final class Order extends BasicAggregateRoot
681718{
682719 #[Id]
@@ -706,10 +743,12 @@ use Patchlevel\EventSourcing\Aggregate\Uuid;
706743use Patchlevel\EventSourcing\Attribute\Aggregate;
707744use Patchlevel\EventSourcing\Attribute\Apply;
708745use Patchlevel\EventSourcing\Attribute\Id;
746+ use Patchlevel\EventSourcing\Attribute\SharedApplyContext;
709747use Patchlevel\EventSourcing\Attribute\Stream;
710748
711749#[Aggregate('shipping')]
712750#[Stream(Order::class)]
751+ #[SharedApplyContext([Order::class])]
713752final class Shipping extends BasicAggregateRoot
714753{
715754 #[Id]
@@ -740,6 +779,11 @@ final class Shipping extends BasicAggregateRoot
740779 }
741780}
742781```
782+ !!! tip
783+
784+ With the [SharedApplyContext](./aggregate.md#shared-apply-context) attribute,
785+ you can suppress missing applies for events that are handled by other aggregates.
786+
743787### Child Aggregates
744788
745789??? example "Experimental"
0 commit comments