Does email transfer relate to presentation level or business application level?

I am trying to find a better area for posting email sending code in my Asp.net MVC application. Now my application is configured in 2 VS projects that separate the business layer from the presentation layer. I am trying to set up a situation where the user reset their password, after the business logic has changed the password, the server will send an email to the user with their new generated password.

Do I have to call a code to send email (including data on how the email looks) from the business layer (after resetting the password for the business layer) or at the presentation level (after the business layer returns a successful result)

+6
source share
5 answers

I partially agree with BobTodd because he offers you to abstract it. The only part in which I (partially) disagree with this happens in the business layer.

Sending email depends on some physical implementation - and you don't want to associate your BLs with external dependencies associated with any email provider.

In a small project, you could include it in BL, I think that everything was simple, but I would prefer to completely abstract it, in which case I would consider it in the same way that I processed Access data.

In my opinion, there are two places in the world that you could put:

  • As a shared service that you can call from anywhere - and because it will be abstracted, you can.
  • As / through the "external service adapter", which is also abstracted out, but accessible only from BL, which, in turn, can expose methods that can call something (for example, the user interface) (if you really wanted to).

5 Layer Architecture

Note. Warning about self-promotion! - taken from one of my own articles: http://morphological.wordpress.com/2011/08/29/5-layer-architecture/

+4
source

Emailing should be part of the business layer.

I encountered the same problem a few weeks ago :, I am creating a web application using asp.net mvc 3, which consists of three projects: Repository (DAL), Services (BLL), Presentation (Web)

My application logic is implemented at the service level, so I was looking for the best way to implement a completely independent module at the service level to send HTML messages to users so that this service level functions can use it directly, without bringing it to the presentation level.

After some searching, I found an elegant solution made by Kazi Manzur, where he created an email subsystem that uses Razor Views to send HTML / Text emails outside of the web proejct.

Use Razor template for email outside ASP.NET MVC

Since then I have been using its subsystem, and it does an excellent job.

+7
source

Sending email is not a presentation level, but you can use the “highlighted presentation layer” to determine how your email looks (design, subject, etc.).

Each "layer" can consist of several independent assemblies.
For instance. You can have more than one species.

+3
source

I prefer to think of things as components that can be disabled using dependency injection.

Create an IEmailService interface with a specific implementation at the business level.

Add it to your controller.

Ask the controller to create and generate a view (a letter from the template) using the model and call the IEmailService implementation to send it.

IEmailService becomes easy to prototype when testing your controller.

+3
source

Email sending is business-level functionality. You will have a mail manipulator class with a method that will send a message and handle exceptions.

0
source

Source: https://habr.com/ru/post/886339/


All Articles