Skip to content

Improve the pattern for initializing aggregates derived from AggregateRoot #100

@joshkempner

Description

@joshkempner

The current pattern, which requires explicitly settings the Source property in the ctor, is non-obvious. We should be able to call base(source) and get the same effect, but we can't do that because we're calling this(). It feels like there should be a better way to do this so that aggregates can use that base ctor instead of having to set Source directly.

One option would be to add the following to the standard pattern for aggregates:

private SomeAggregate(ICorrelatedMessage source) : base(source)
{
    RegisterEvents();
}
private SomeAggregate(
    /* other parameters */
    ICorrelatedMessage source)
    : this(source)
{
    ...
}

I believe we need to keep the parameterless ctor for deserialization, but this would give a slightly cleaner pattern for devs to use.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions