Hi Andrew. In your excellent series of blog posts on Strongly Typed Id's, you make mention of some downsides to using a struct to model identity versus a class, due to implicit parameterless constructors. You also cite Vladamir Khorikov's article on the subject who makes further arguments for not choosing a struct for modelling identity and favoring a class. Classes have their downsides too of course, not least of which is having to null-check them all over the place, so they're not a panacea, but if you're trying to follow DDD best practices where protection of invariants is paramount, a class-based option would be desirable.
So, with all that said, have you considered enabling class-based strongly typed identifiers in your library in addition to struct-based ones?
Hi Andrew. In your excellent series of blog posts on Strongly Typed Id's, you make mention of some downsides to using a
structto model identity versus aclass, due to implicit parameterless constructors. You also cite Vladamir Khorikov's article on the subject who makes further arguments for not choosing astructfor modelling identity and favoring aclass. Classes have their downsides too of course, not least of which is having tonull-check them all over the place, so they're not a panacea, but if you're trying to follow DDD best practices where protection of invariants is paramount, aclass-based option would be desirable.So, with all that said, have you considered enabling
class-based strongly typed identifiers in your library in addition tostruct-based ones?