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

Shared functionality between two or more use cases #46

Open
stackus opened this issue May 18, 2020 · 0 comments
Open

Shared functionality between two or more use cases #46

stackus opened this issue May 18, 2020 · 0 comments

Comments

@stackus
Copy link

stackus commented May 18, 2020

Thanks for this repo btw.

How would you go about putting in functionality that would be shared between two or more use cases? An example is emailing and the building of those emails from templates.

User or Registration domain with a usecase that will need to send user registration emails
Order domain with a usecase that will need to send order confirmation emails
EmailRepository that does the work of sending the emails
TemplateRepository or AssetRepository that does the work of locating templates

I might do something like the following

EmailRepository
  - sends the emails through an email provider or service
  - Send(email domain.Email) error
TemplateRepository
  - locate templates from the file system, a database, bindata, or other
EmailService or EmailManager
  - contains the logic of turning templates and data into email entities
  - is a domain service it will not use any repositories
  - BuildConfirmationEmail(data {TBD dataType}, templates {TBD templatesType}) domain.Email
OrderUsecase
  - uses EmailRepository, TemplateRepository, EmailService
  - is an application service and uses repositories and domain services

When the User and Order domains want to send emails they'll need to rely on the same three dependencies. This might be OK but I'm not sure and I might have confused a concept or three and that has me tangled up in this knot.

If there were a report component to the application, it may use the same templates repository but would output CSV, Excel, or PDF documents instead. Having a template or assets domain makes sense, I just haven't found the right approach to bringing it together with the logic and other repositories in a shared manner that is used in different usecases that sits well with me.

edit: Giving this some thought and the email problem would probably be best solved using Domain Events. So instead of operating on the aggregate in the User domain performing registration and also sending the email. I would register the user then raise a UserRegistered event that would at minimum have a listener in the Email domain. There the email could be built from templates, or anything, then sent out.

A bonus question regarding this current layout and imports. When there's a handful, say 8-10, modules to import things from do you have any suggestions on organizing or reducing them?

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

1 participant