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

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

问题描述

我试图找出最好的代码,在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中,我想,为了保持简单, d赞成完全抽象出来,在这种情况下,我会对待它就像我会对待数据访问。

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://形态。 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天全站免登陆