发送电子邮件属于应用程序的表示层还是业务层? [英] Does sending an email belong in the presentation layer or business layer of an application?

查看:37
本文介绍了发送电子邮件属于应用程序的表示层还是业务层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出在我的 Asp.net MVC 应用程序中放置代码以发送电子邮件的最佳区域.现在我的应用程序设置在 2 个 VS 项目中,将业务层与表示层分开.我正在尝试设置一种情况,当用户重置密码时,在业务逻辑更改密码后,服务器将使用新生成的密码向用户发送电子邮件.

I am trying to figure out the best area to place code to send an email in my Asp.net MVC application. Right now my application is setup in 2 VS projects separating out the business layer from the presentation layer. I am trying to setup a situation that when a user reset's their password, after the business logic changes the password the server will send an email to the user with their newly generated password.

我应该调用代码从业务层(业务层重置密码后)还是在表示层(业务层返回成功结果后)发送电子邮件(包括有关电子邮件外观的数据)?

Should I be calling the code to send the email (including data on how the email looks) from the business layer (after the business layer resets the password) or in the presentation layer (after the business layer returns a successful result)?

推荐答案

我部分同意 BobTodd 的观点,因为他建议您将其抽象出来.我(部分)不同意的唯一部分是它进入业务层.

I partially agree with BobTodd because he's suggesting you abstract it out. The only part where I (partially) disagree is about it going in the business layer.

发送电子邮件依赖于某种物理实现 - 您不希望将您的 BL 与与某些电子邮件提供商相关的外部依赖联系起来.

Sending email is dependent on some sort of physical implementation - and you don't want to tie your BL to outside dependencies related to some email provider.

在一个小项目中,你可以将它包含在 BL 中,我想,为了让事情变得简单,但我赞成将它完全抽象出来,在这种情况下,我会像对待数据一样对待它访问.

In a small project you could include it in the BL, I guess, to keep things simple but I'd be in favor of abstracting it out completely, in which case I'd treat it just like i'd treat data Access.

在我看来,你可以把它放在两个地方:

In my view of the world there's two places you could put it:

  • 作为一种共享服务,您可能想从任何地方调用它 - 因为它会被抽象出来,所以您可以这样做.
  • 作为/通过外部服务适配器",它也被抽象出来,但只能从 BL 访问 - 这可能反过来公开任何东西(如 UI)都可以调用的方法(如果你真的想要的话).
  • 莉>

注意:自我宣传提醒!- 摘自我自己的一篇文章:http://morphological.wordpress.com/2011/08/29/5-layer-architecture/

Note: Self promotion alert! - taken from one of mine own articles: http://morphological.wordpress.com/2011/08/29/5-layer-architecture/

这篇关于发送电子邮件属于应用程序的表示层还是业务层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆