IDDD_Samples_NET icon indicating copy to clipboard operation
IDDD_Samples_NET copied to clipboard

EventSourcedAggregateRoot dynamic apply

Open leonfs opened this issue 11 years ago • 1 comments

   void When(IDomainEvent e)
    {
        (this as dynamic).Apply(e);
  }

    protected void Apply(IDomainEvent e)
    {
        this.mutatingEvents.Add(e);
        When(e);
    }

This code doesn't work, it generates an StackOverflow exception due to it's infinite recursion.

leonfs avatar Jan 28 '14 10:01 leonfs

Ahh yes, this is the proper implementation - http://blogs.msdn.com/b/davidebb/archive/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code.aspx

As seen here - https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/InfrastructureCrap.DontBotherReadingItsNotImportant.cs

eulerfx avatar Jan 28 '14 14:01 eulerfx