-
Notifications
You must be signed in to change notification settings - Fork 40
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
Public parameterless constructor required in order to use generic ValueOf<TValue, TThis> #13
Comments
Do you mean there should be a parameterless instance constructor? |
I think he means the problem that the library does not prohibit this:
So later on, when you start using the type, you will get some NullReference exceptions. I am not sure if the expectation of everyone playing nice and using the factory method is a good one. Having a mandatory constructor of T instead would make the wrting of the classes a little bit more ugly, but would get rid of this problem. |
I had a very similar library to this one, with the major difference being that validation wasn't optional as it was required in the constructor, e.g. public class Age : ValueObject<int>
{
public Age(int value) : base(value, x => x < 0 : "negative age" : string.Empty) { }
} The base class would call the provided delegate and throw if it returned anything other than an empty string. The down side is two heap allocations, one for the instance itself, and one for the delegate. |
I think the requirement of a parameterless constructor should be fixed in order to avoid the creation of invalid objects which is an antipattern regarding DDD
The text was updated successfully, but these errors were encountered: