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

Removed the requirement for having the default constructor in the aggregation process and projections #1447

Merged
merged 5 commits into from
May 13, 2020

Conversation

oskardudycz
Copy link
Collaborator

@oskardudycz oskardudycz commented Apr 2, 2020

Overview

Currently, Marten forces in many places new () constructor. This is not a huge issue, but a bit painful and sometimes too big restriction. For most of the guides of how to construct proper aggregates (and classes in general), it stated that they should only expose what's needed. Usually, it's good to not expose the public default constructor but use the dedicated factory method.

Especially for the event-sourced aggregates, it's important, as the state should be rebuilt from the events.

Details of changed

Introduced new object factory called (surprise!) New. This solution is taken from https://stackoverflow.com/a/16162475/10966454.

See also more benchmarks and discussion about object creation from lambda (with expression caching):

The solution tries to find the default public constructor, if it's not able then it's searching for non-public and this is also not found then it creates an uninitialized object (see https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatterservices.getuninitializedobject?view=netframework-4.8).

Besides that:

  • added necessary tests,
  • updated aggregate & repository case study,
  • updated documentation with information about object creation,
  • copied .editorconfig file to be located in the same folder as marten solution file (this is required to have rules properly applied).

…gregate and repository to agregate not need to have public constructor.
…Moved .editorconfig file to be located where solution file
…that it does not need the default constructor anymore.
@oskardudycz oskardudycz marked this pull request as ready for review May 12, 2020 18:48
@oskardudycz oskardudycz added this to the 3.12.0 milestone May 12, 2020
@oskardudycz oskardudycz requested review from mysticmind, jokokko and jeremydmiller and removed request for mysticmind and jokokko May 12, 2020 18:48
Copy link
Member

@jeremydmiller jeremydmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oskardudycz I think this all looks good to me.

@oskardudycz oskardudycz merged commit ccf3572 into master May 13, 2020
@oskardudycz oskardudycz deleted the feature/RemoveTheDefaultConstructorRequirement branch May 13, 2020 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants