Using Postal Library From the Business Layer

做~自己de王妃 提交于 2019-12-05 10:12:56

Could you not just wrap your email logic behind a service layer or infrastructure or whatever and call it from the controllers, and inject the service via your constructor? You do the same with your business layer. Unless the postal object requires something inherit to asp.net ?

namespace ProjectName.Infrastructure
{
    public interface IEmailService
    {
        void SendEmail(string address, string content)
        {
        }
    }

    public class EmailService : IEmailService
    {
        private void SendEmail(string address, string content)
        {
            //...send email via Postal
        }
    }
}

public class ControllerA
{
    private IEmailService emailService;

    public ControllerA()
    {
        emailService = new EmailService();
    }

    public ActionResult SendEmail(ViewModel model)
    {
        emailService.SendEmail(model.address, model.content);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!