Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the pattern for initializing aggregates derived from AggregateRoot #100

Open
joshkempner opened this issue Oct 28, 2021 · 0 comments
Assignees

Comments

@joshkempner
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant