Skip to content

Should UserIdGenerator really be considered a domain concept? #39

Answered by ivan-borovets
dbealthy asked this question in Q&A
Discussion options

You must be logged in to vote

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 like UserId(0) and let the DB assign the real ID later:

  1. Value object for ID
@dataclass(frozen=True, repr=False)
class UserId(ValueObject):
    value: int
  1. User Service
def create_user(self, ...) -> User:
    user_id = UserId(0)
    ...
    return User(id_=user_id, ...)
  1. Users Table Mapping
users_table = Table(
    "users",
    mapping_registry.metadata,
    Colum…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ivan-borovets
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Improvements or additions to documentation question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #30 on May 30, 2025 00:08.