Search code examples
oopdomain-driven-designdomain-service-class

SendEmail method in Member service?


I have a requirement to send daily emails to members of the system. I would like to know if SendMail method should be in MemberService or should I create separate service class for this?

Appreciate any help.

Thanks APL


Solution

  • Initially, without jumping to complexity, you may begin by placing the SendEmail method on MemberService which could have a dependency on an email service abstraction. Given that the sending of a daily email isn't a response to a domain event or even business logic handled explicitly by your domain, you can move the email sending method out of MemberService, however you still need to provide a query on a repository which returns a list of members eligible for daily emails. The sending application would likely be hosted in a scheduled process which has the sole responsibility of sending emails. As such, it isn't necessary for it to have all the other functionality associated with the member service. It only needs to pull a list of members and send emails, perhaps with a templating engine.