Skip to content
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

State in domain services #52

Open
ErikJson opened this issue Aug 16, 2023 · 3 comments
Open

State in domain services #52

ErikJson opened this issue Aug 16, 2023 · 3 comments

Comments

@ErikJson
Copy link

Hi,

In the book, it's clearly stated that domain services should be stateless. However, we noticed that BusinessPriorityCalculator (and possibly other services) do store a repository reference.

We can see why this may not be an issue in practice, given that BacklogItemRepository should be a singleton, but we don't know if that's the reason why this exception was made.

What rules of thumb do you use when sidestepping the "services should be stateless" rule? Thanks!

@VaughnVernon
Copy link
Owner

It's free of business state. Technical state is fine, and it's typical for a Domain Service to use a Repository.

@ErikJson
Copy link
Author

Thanks for your response, Vaughn.

The terms "business state" and "technical state" are a bit vague to me, and I can't find good resources on them. As far as I can tell they are not covered in the book.

We believe ourselves to have a decent understanding of what can and cannot be stored as class properties on the service, e.g. we wouldn't think to store the tenant or product IDs as properties on BusinessPriorityCalculator, so we'll proceed with the assumption that we can trust our judgment rather than a set of clear rules.

@VaughnVernon
Copy link
Owner

Your assumption is correct. Associating any business-specific data (model objects) with a Domain Service beyond a single operation is the wrong decision.

A Repository is technical state to make it convenient to use one or more Aggregates in the business operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants