Skip to main content
deleted 1 character in body
Source Link

It seems that MailService should only have one MailerServiceDelegate during it's lifetime. I am not sure if you can change MailService, but I think that it's current implementation have some flaws.

If you can not change MailService, then the best option is to use your own adapter on MailService which will contain multiple MailServices instances, for each email sending methodMailServiceDelegate:

public class MailServiceAdapter {
    
    MailService _emailResetService;
    MailService _otherMailService;

    public MailServiceAdapter(MailServiceFactory mailServiceFactory){
        _emailResetService = mailServiceFactory.CreateMailResetService();
        _otherMailService = mailServiceFactory.CreateOtherMailService();
    }
    public void sendEmailAddressResetRequest(UserAccount userAccount, EmailReset emailReset)
    {
         _emailResetService.sendEmail(userAccount, emailReset);
    }

    public void sendOtherStuff(UserAccount userAccount, OtherEmail otherEMail)
    {
         _otherMailService.sendEmail(userAccount, otherEMail);
    }
}

It seems that MailService should only have one MailerServiceDelegate during it's lifetime. I am not sure if you can change MailService, but I think that it's current implementation have some flaws.

If you can not change MailService, then the best option is to use your own adapter on MailService which will contain multiple MailServices instances, for each email sending method:

public class MailServiceAdapter {
    
    MailService _emailResetService;
    MailService _otherMailService;

    public MailServiceAdapter(MailServiceFactory mailServiceFactory){
        _emailResetService = mailServiceFactory.CreateMailResetService();
        _otherMailService = mailServiceFactory.CreateOtherMailService();
    }
    public void sendEmailAddressResetRequest(UserAccount userAccount, EmailReset emailReset)
    {
         _emailResetService.sendEmail(userAccount, emailReset);
    }

    public void sendOtherStuff(UserAccount userAccount, OtherEmail otherEMail)
    {
         _otherMailService.sendEmail(userAccount, otherEMail);
    }
}

It seems that MailService should only have one MailerServiceDelegate during it's lifetime. I am not sure if you can change MailService, but I think that it's current implementation have some flaws.

If you can not change MailService, then the best option is to use your own adapter on MailService which will contain multiple MailServices instances, for each MailServiceDelegate:

public class MailServiceAdapter {
    
    MailService _emailResetService;
    MailService _otherMailService;

    public MailServiceAdapter(MailServiceFactory mailServiceFactory){
        _emailResetService = mailServiceFactory.CreateMailResetService();
        _otherMailService = mailServiceFactory.CreateOtherMailService();
    }
    public void sendEmailAddressResetRequest(UserAccount userAccount, EmailReset emailReset)
    {
         _emailResetService.sendEmail(userAccount, emailReset);
    }

    public void sendOtherStuff(UserAccount userAccount, OtherEmail otherEMail)
    {
         _otherMailService.sendEmail(userAccount, otherEMail);
    }
}
Source Link

It seems that MailService should only have one MailerServiceDelegate during it's lifetime. I am not sure if you can change MailService, but I think that it's current implementation have some flaws.

If you can not change MailService, then the best option is to use your own adapter on MailService which will contain multiple MailServices instances, for each email sending method:

public class MailServiceAdapter {
    
    MailService _emailResetService;
    MailService _otherMailService;

    public MailServiceAdapter(MailServiceFactory mailServiceFactory){
        _emailResetService = mailServiceFactory.CreateMailResetService();
        _otherMailService = mailServiceFactory.CreateOtherMailService();
    }
    public void sendEmailAddressResetRequest(UserAccount userAccount, EmailReset emailReset)
    {
         _emailResetService.sendEmail(userAccount, emailReset);
    }

    public void sendOtherStuff(UserAccount userAccount, OtherEmail otherEMail)
    {
         _otherMailService.sendEmail(userAccount, otherEMail);
    }
}