CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

System.Net.Mail, create a new object just for mailling? Encapsulation question

Last post 08-26-2008, 4:37 PM by richardb. 3 replies.
Sort Posts: Previous Next
  •  08-21-2008, 10:03 PM 25650

    System.Net.Mail, create a new object just for mailling? Encapsulation question

    I have an alert system in my application where we save users messages to one another in our SQL database.  Now our users would like us to start emailing notifications for those messages. 

    I have a Message object and MessageRecipient objects and a collection to hold them. These are CSLA objects that I use to create a new message, set subject, body, and other properties and then add recipients to the MessageRecipients child collection.  All of our data is stored in sql database and then we have other methods that show these messages on our users Alert pages.

    So now I need to have some kind of .SendEmailNotifications method that is going to use the System.Net.Mail to take these properties and recipients and send the emails.  I'm trying to decide where to put this.  Whether I should add a static method to the Message class, Message.SendEmailNotifications that checks the recipients properties to see if they recieve email alerts or not and then sends the emails.  Or, should I create some kind of Mailer object that has properties Subject, Body, etc. and then has .AddEmailRecipient(userID) method to add email reciepients, then finally a .SendEmail method to send it all.

    So should I keep it in my existing Message object or create a seperate Mailer object?  What do you think?

  •  08-22-2008, 8:22 AM 25668 in reply to 25650

    Re: System.Net.Mail, create a new object just for mailling? Encapsulation question

    I've previously created a seperate class library for this sort of thing so it can be re-used across many projects.

    So I have my wrapper class around the System.Net.Mail and then versions of SendMessage methods that can take a simple string, or message object, etc. 

     

  •  08-25-2008, 9:48 AM 25715 in reply to 25668

    Re: System.Net.Mail, create a new object just for mailling? Encapsulation question

    That's where I was going but as I began writing the wrapper it just seemed like I was writing the same class but just renaming the methods.  All it really did was store a few things like my smtp credentials.  I suppose that may be enough to justify a new class, not having to deal with that.  I'm still not sure.
  •  08-26-2008, 4:37 PM 25753 in reply to 25715

    Re: System.Net.Mail, create a new object just for mailling? Encapsulation question

    That's true, but you never know how Microsoft might change things in the future and wrapping the functionality in your own class might help reduce the upgrade effort later.
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems