Should UserIdGenerator really be considered a domain concept? #39
-
I started following structure from this great example to implement clean architecture in my project. While implementing the CreateUserInteractor use case, i noticed that UserService depends on UserIdGenerator from domain layer. But in my case i want user id to be auto incremented, so i would have to pull that id from db, and it would be an application level concept then. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Thanks for the warm feedback about the project — glad it's been helpful! I see what you're running into. Whether
If you're switching from UUIDs, just make sure to update the rest of the code accordingly. |
Beta Was this translation helpful? Give feedback.
-
Thanks. The example helped a lot. I was thinking about moving UserIdGenerator into the application layer and implementing it in the infrastructure layer, querying next id from db like this: SELECT nextval(pg_get_serial_sequence('users', 'id'));
|
Beta Was this translation helpful? Give feedback.
-
Since you're already leaning towards using auto-increment, it might be easier to stick with that and let the DB handle ID assignment at insert time. UPD: See my corrected response below. |
Beta Was this translation helpful? Give feedback.
-
Apologies! I missed the atomic nature of |
Beta Was this translation helpful? Give feedback.
Thanks for the warm feedback about the project — glad it's been helpful!
I see what you're running into. Whether
UserIdGenerator
belongs in the domain really depends on how you handle ID generation. It's likely unnecessary if IDs are assigned by the database (e.g. via auto-increment). In that case, you can use a placeholder likeUserId(0)
and let the DB assign the real ID later: