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?
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:
- We decided to create a EmailController for mail rendering. This controller had the [AllowAnonymous] attribute applied on it.
- The views created by the controller actions did not contain any business relevant information just their models! Not that someone calls it by accident :)
- 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!