NEventLite
NEventLite copied to clipboard
Question about the new() generics constraint on aggregate classes
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.
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