DDD: MailService.SendNotificationToUser() or User.Notify()?

Posted by cfs on Stack Overflow See other posts from Stack Overflow or by cfs
Published on 2012-03-21T17:26:25Z Indexed on 2012/03/21 17:29 UTC
Read the original article Hit count: 117

Filed under:

I seem to stumble on problem after problem giving my entities behavior.

I have a system where a user gets a notification when someone comments his article. Right now it is via an e-mail.

I'm struggeling how to implement this the DDD way.

Option 1

User entity has a Notify method: User.Notify() The method uses C# built in classes to send an e-mail notification via e-mail

The problem with having this in the domain is that it is technology spesific, and how a user is notified might change in the future. I feel this belongs to infrastructure, but how then can a user have behavior?

Option 2

I create a Service: NotificationService.Notify(User) The Service uses C# built in classes to send an e-mail

The pro is that the service could be an Application Service, and as far as I know an application service can use the infrastructure and call things like the System.Net.Mail and repositories for that sake.

How would you implement this?

© Stack Overflow or respective owner

Related posts about c#-4.0