Email sending architecture in Domain Driven Architecture

Our team had recently the challenge to create an email sending functionality. This shouldn’t be a big deal, right?
For our solution we decided to render our email views with our MVC Web Project. When one starts to implement that in a strict architecture, then some problems arise:

  • What if a Worker/Windows Service “want” to send an email?
  • How to send an email from the domain layer?

Our current architecture is not completely Domain Driven however the solution what I’m going to provide, can easily applied.
I sketched it fast, so that you see the problem visually represented:
SimplifiedArchitecture

Ideally we would want to place the email generation logic into the Application Services however there are multiple problems with that. We didn’t wanted to have System.Web references there and so on…

Our solution looked like the following in the end:

  1. We decided to create a EmailController for mail rendering. This controller had the [AllowAnonymous] attribute applied on it.
  2. The views created by the controller actions did not contain any business relevant information just their models! Not that someone calls it by accident :)
  3. Our Application Service called an adapter useing the System.Net.WebClient to post the models for the views

In this way we used our Presentation Layer as a Service. This provides us nice looking HTML views conform to our web applications look and feel. We didn’t needed any hacks for using System.Web references anywhere in the application. So all in all I’m really happy with this solution – hopefully someone can use it!

We have been working this solution out together with TJ, check out his website as well!

Advertisements

About Tamas Nemeth

Husband and proud father of two daughters in Nürnberg. I'm working as a Senior Software Developer and an enthusiastic Clean-Coder. I spend most of my free time with my family (playing, hiking, etc...). I also play table-tennis and badminton sometimes...
This entry was posted in Technical Interest and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s