The services namespace provides runtime services, such as email processing, alert management, and task-scheduling.

Services are defined in metadata and can contain properties for configuration. A Service references a component and that component must implement the IServiceInfo interface.

Services can be marked as Singleton. This means that the application context object will create only one instance of the service for the life of the application.

Classes

  ClassDescription
Public classAlertService
The standard platform alert service. Currently alerts are provided via AJAX while users are logged into the application.
Public classMailEventArgs
Event args used with mail events, e.g. MailBeforeSend and MailAfterSend.
Public classMailService
The MailService object is a wrapper object around System.Web.Mail that can load it's configuration properties from the repository database or used stand alone.
Public classNamespaceDoc
Public classServiceBase
Simple implementation of a service
Public classServiceInfos
Holds a collection of services
Public classUserSettingsRequiredException
Exception thrown when required user email settings have not been configured.

Interfaces

  InterfaceDescription
Public interfaceIAlertService
Interface implemented by services providing alerts to users.
Public interfaceIDocStorageService
Interface that implements document storage.
Public interfaceIEmailService
Interface that implements an email service.
Public interfaceIServiceInfo
Interface implmented by core services.

Enumerations

  EnumerationDescription
Public enumerationEmailSendAttrs
Controls email send behavior.
Public enumerationMailerAttrs
Attributes describing aspects of an email message.
Public enumerationSendEmailFlags
Public enumerationServiceAttrs
Service attributes
Public enumerationSmtpAuthenticationType
Specifies the authentication mechanism to use when authentication is required to send messages to an SMTP service using a TCP/IP network socket.

Examples

The following example shows how to obtain a reference to the email service and send a message using a template.
CopyC#
private void Send(IAppContext appContext, string sendToList, string templateName, NameValueCollection nameValues)
{
    ServiceInfos        svs = appContext.Services;
    IEmailService        mail = (IEmailService)svs.GetServiceInstance("SmtpMail");            
    NetQuarry.Template    tmpl = appContext.Templates[templateName];
    string                body;
    string                subject;

    if (tmpl == null)
        throw new ApplicationException(string.Format(this.TextItems.GetText(IDS_MISSING_TEMPLATE), templateName));

    body = tmpl.Replace(nameValues);
    subject = tmpl.TextItems.GetText("Subject");

    try
    {
        //--- leave the From field empty, it will default to the value configured in the studio
        mail.Send(string.Empty, sendToList, subject, body, true);
    }
    catch(Exception ex)
    {
        //--- log the error then re-throw
        DevLog.LogMessage("XIssue.Send", "sendMailError", ex);
        throw;
    }
}

See Also