Closed mbadolato closed 11 years ago
@beberlei TL:DR - This is a fix needed because CRUD traits are currently unusable unless AggregateResource is extended. But if AggregateResource is the extended class, then CRUD traits don't even need to be used. However, sometimes AggregateResource cannot be the extended class, thus a trait is necessary.
@beberlei Is this ok to merge or do you require any additions/changes?
Just discovered why apply() may not be in there; redeclaration error if more than one trait is imported into a class
The methods in the Plugin/CRUD/Crud* trait classes call out to an apply method (which in turn calls the trait's applyResource* methods), which does not exist in the trait class definition.
This means that the CRUD plugin cannot be used with entity objects that extend DomainEventProvider, as that class doesn't provide an apply method. Instead, Aggreagte Resource would need to be extended, which extends AggregateRoot, which means the entity would no longer have access to raise() events.
Since the Crud traits are near duplicate methods to versions in CRUD/AggregateResource and AggregateRoot anyway, there's no point in using the traits, when you could just extend AggregateResource instead.
But for when AggregateResource cannot be the extended class, the traits are needed, therefore the entire call chain needs to be available, so that we don't violate DRY by re-implementing apply() in every Entity object that extends DomainEventProvider but needs the create/update/delete crud traits