Fluent Interface Design in .NET: Listing 3

Full EmailSender fluent API implementation.

EmailSender.Fluent.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VSMFluentInterfaces.Email.Fluent;
 
namespace VSMFluentInterfaces.Email
{
    public partial class EmailSender : IFluentEmailSender
    {
        EmailMessage _message;
 
        public IFluentEmailSender FromServer(string host)
        {
            EmailServer = host;
            return this;
        }
 
        public IFluentEmailSender WithCredentials(string username, string password)
        {
            SetCredentials(username, password);
            return this;
        }
 
        public IFluentEmailMessage CreateEmail()
        {
            _message = new EmailMessage(this);
            return _message;
        }
 
        public void Send()
        {
            Send(_message);
        }
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at vogelvision@gmail.com.