开发者

Which layer is appropriate to place the function to send mail?

开发者 https://www.devze.com 2023-02-08 05:08 出处:网络
I\'m designing Java Web application framework. The framework is applied the typical 3 layers as architecture, presentation/business/integration.

I'm designing Java Web application framework. The framework is applied the typical 3 layers as architecture, presentation/business/integration.

Generally, I think the definition of business layer is "The business login not depending to the concrete implementation of persistence process" and integration layer is "the concrete implementation of persistence process".

Here, I'm wondering w开发者_StackOverflow社区hich layer is appropriate to place the function to send mail. My opinion is, as a rule, business layer should not access outside of the system directly, so sending mail should be placed in the integration layer though it doesn't access to DB or any persistence. By the reason, functions like reading config files are the same, too.

I want to decide the rule with considering of various opinion, so please tell me your opinion with the reason.

P.S. Here "sending mail" doesn't mean the processes like desiding to send, composing message, selecting the destination. I think it's a duty of business layer. Here "sending mail" just means the sending procedure itself.


In my opinion, Business layer should decide,build mail message and notify integration layer to send an email (communicate with external system). Actual mail should be sent by integration layer


I have it in business-layer, it contains complete logic to create appropriate message, fetch appropriate receivers and finally, use a service to send-mail that encapsulates logic to just take the sender, message and receivers and returns status.


Edit after new addition to the question.

The mailing module should be a business-service, it should be in service-layer. A service layer that is reusable. If you have a larger project with multiple apps, they all can use this mailing module from service-layer to send the mail.

So, speaking in your language, mailing process is a subsystem of business layer that should be reused.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号