white-label
white-label copied to clipboard
What is the difference between id & userId?
export class User extends AggregateRoot<UserProps> {
get id (): UniqueEntityID {
return this._id;
}
get userId (): UserId {
return UserId.caller(this.id);
}
get email (): UserEmail {
return this.props.email;
}
.
.
.
}
Why are there two id attributes in class User? one is named id and the other userId.
Why not use id : UniqueEntityID for all aggregates?
Also, the Function.caller seems to be deprecated.
The ID identifies that unique entity in this moment and it's always an UUID,
You do not use this as UserID for a few possible reasons ( You can, but you force your design to this ):
- Force your User domain entity to have an UUID as ID, so you won't be able to use a DB generated ID
- You force the Value object of your Domain entity
- In this model the way of working with UniqueEntityID Is not the same rather than working with Entity props
You can, of course you can but your force your domain model to work this way. The way that UniqueEntityID is build for.
Remember that is your have constraints for your domain model, in terms of identity that in your question, will be handled by UniqueEntityID class, you will have to modify this one, doing this you will be modifiying all the rest of ID's that well, for 1 function this won't be a big problem but in the long term that class, being used this way could have a big chance to become a big ball of mud.