Skip to content

In the ClassifiedAd class, the Picture collection is not instantiated when doing a re-hydrate. #3

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

Open
paulvanbladel opened this issue Jun 7, 2019 · 1 comment

Comments

@paulvanbladel
Copy link

paulvanbladel commented Jun 7, 2019

The ClassifiedAdd class has:

  public List<Picture> Pictures { get; private set; }

which is initialized in the following constructor:

 public ClassifiedAd(ClassifiedAdId id, UserId ownerId)
        {
            Pictures = new List<Picture>();
            Apply(
                new Events.ClassifiedAdCreated
                {
                    Id = id,
                    OwnerId = ownerId
                }
            );
        }

That's working fine but not in the re-hydrate scenario because the aggregate root doesn't touch that constructor when the event sourcing machinery is setting up via reflection the aggregate root.
A potential fix is to initialize the collection directly as follows:

public List<Picture> Pictures { get; private set; } = new List<Picture>();
@alexeyzimarev
Copy link
Collaborator

The best solution would be to use property initialiser. I will check the code as soon as I am done with Chapter 13.

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

No branches or pull requests

2 participants