NEventLite icon indicating copy to clipboard operation
NEventLite copied to clipboard

Question about the new() generics constraint on aggregate classes

Open cmrdY opened this issue 3 years ago • 1 comments

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.

cmrdY avatar Aug 10 '20 20:08 cmrdY

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

dasiths avatar Aug 11 '20 15:08 dasiths