Closed mrmorrandir closed 5 months ago
We have different scanarios this "bug" would be possible:
Guid
s. The "bug" was part of a test-scenario, where more than one aggregate was created (by hand) with the same id. This should/would never happen in the field under normal circumstances. EventRespository
with the id of another Aggregate type that he might have used before.In both scenarios it would only be possible to return Result.IsFailed
when the type of the aggregate would be stored in the EventStore
. Meaning that the EventData
entity would need an StreamType
together with the StreamId
to identify the stream. (The current Type
property only identifies the event type)
In most cases the protected abstract void AggregateRoot.Apply
method would/should throw an exception when an event with unknown event-type should be applied.
public sealed class ProcessAggregate : AggregateRoot
{
// ... properites, constructors, methods ...
protected override void Apply(IEvent @event)
{
switch (@event)
{
case ProcessCreated e:
Id = e.Id;
Created = e.Created;
Country = e.Country;
Plant = e.Plant;
Line = e.Line;
Name = e.Name;
Equipment = e.Equipment;
Material = e.Material;
MaterialText = e.MaterialText;
Order = e.Order;
State = ProcessState.Pending;
Result = ProcessResult.Unknown;
Data = e.Data;
break;
case ProcessStarted e:
State = ProcessState.Active;
break;
case ProcessFinished e:
State = ProcessState.Finished;
Finished = e.Finished;
Result = e.Result;
break;
case ProcessCancelled e:
State = ProcessState.Cancelled;
break;
// This default case would be needed to get an error
default:
throw new UnkownEventException($"The event type {e.GetType()) could not be processed by {GetType) (Aggregate)!");
}
}
}
Implementing the default:
case would be in the responsibility of the developer which seems legitimate to me.
When using a
streamId
(hererequest.Id
) of anAggregate
type that differs from the type parameter, theEventRespository
should return aIsFailed
result, but returnsIsSuccess
.Example: We want to request a
ProcessAggregate
from theEventRepository
but thereqeuest.Id
is that of aProcessStepAggregate
(which does exist in the event store)