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

Question about the new() generics constraint on aggregate classes #12

Open
cmrdY opened this issue Aug 10, 2020 · 1 comment
Open

Question about the new() generics constraint on aggregate classes #12

cmrdY opened this issue Aug 10, 2020 · 1 comment

Comments

@cmrdY
Copy link

cmrdY commented Aug 10, 2020

Hi @dasiths, thank you for your work.

Just a question,
in /src/NEventLite/Repository/Repository.cs (the CreateNewInstance() method), is it necessary to force a public parameter-less constructor to be defined on the aggregate class?
Why not something like this?
return (TAggregate)Activator.CreateInstance(typeof(TAggregate), nonPublic: true);

Thank you in advance. I am new to Github so I am sorry if I am not doing this right.

@dasiths
Copy link
Owner

dasiths commented Aug 11, 2020

Hi @cmrdY...
When I designed it I wanted the aggregate class ctor and mutating methods to be public. A good case for this is unit testing. Is there any reason why you think the ctor should be private?

Apart from that new() and Activator.CreateInstance() do the same thing https://stackoverflow.com/questions/1649066/activator-createinstancet-vs-new

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

No branches or pull requests

2 participants