Umbraco uses Notifications (similar to the Observer pattern) to allow you to hook into the workflow process for the backoffice. For example, notifications allow you to execute some code every time a page is published.
Notifications
All notifications reside in the Umbraco.Cms.Core.Notifications namespace and are postfixed with Notification.
Available notifications typically exist in pairs, with "before" and "after" notifications. For example, the ContentService class has the concept of publishing and published notifications. So, there is both a ContentPublishingNotification and a ContentPublishedNotification notification.
The notification to use depends on what you want to achieve. If you want to be able to cancel the action, you would use the CancelOperation method on the "before" notification. See the sample in . If you want to execute some code after the publishing has succeeded, then you would use the "after" notification.
Registering Notifications
Check the article to learn more about notification handlers lifetime, async notification handler and how to register the notification handlers.
List of Notifications
Below you can find a list of most used object notifications.
You can find a list of all supported notifications in the .
Content, Media, and Member notifications
ContentService Notifications
The ContentService class is the most commonly used type when extending Umbraco using notifications. ContentService implements IContentService. It provides access to operations involving IContent.
Below you can find a list of the most common ContentService object notifications.
MediaServiceNotifications
Below you can find a list of the most common MediaService object notifications.
MemberService Notifications
The MemberService implements IMemberService and provides access to operations involving IMember.
Below you can find a list of the most common MemberService object notifications.
Other notifications
ContentTypeService Notifications
The ContentTypeService class implements IContentTypeService. It provides access to operations involving IContentType.
Below you can find a list of the most common ContentTypeService object notifications.
MediaTypeService Notifications - object list
The MediaTypeService class implements IMediaTypeService. It provides access to operations involving IMediaType.
Below you can find a list of the most common MediaTypeService object notifications.
MemberTypeService Notifications
The MemberTypeService class implements IMemberTypeService. It provides access to operations involving IMemberType
Below you can find a list of the most common MemberTypeService object notifications.
DataTypeService Notifications
The DataTypeService class implements IDataTypeService. It provides access to operations involving IDataType.
Below you can find a list of the most common DataTypeService object notifications.
FileService Notifications
The FileService class implements IFileService. It provides access to operations involving IFile objects like scripts, stylesheets and templates.
Below you can find a list of the most common FileService object notifications.
LocalizationService Notifications
The LocalizationService class implements ILocalizationService. It provides access to operations involving Language and DictionaryItem.
Below you can find a list of the most common LocalizationService object notifications.
CacheRefresher Notifications
Below you can find a list of the most common CacheRefresher object notifications.
RelationService Notifications
Below you can find a list of the most common RelationService object notifications.
The RelationService provides access to operations involving IRelation and IRelationType, and publishes the following relation notifications:
UmbracoApplicationLifetime Notifications
Represents an Umbraco application lifetime (starting, started, stopping, stopped) notification.
Below you can find a list of the most common UmbracoApplicationLifetime object notifications.
Tree notifications
Editor Model Notifications
Useful for manipulating the model before it is sent to an editor in the backoffice. It could be used to set a default value of a property on a new document.
Creating and publishing your own custom notifications
Showing messages in the CMS
When handling notifications for CMS actions, you can inform the Umbraco user of the status of your notification. This is done by adding to the notification.Messages property within the Handle function.
This could be used to inform the user to an additional operation that has been performed, or alert them to an error that has occoured.
For example, in a ContentTypeSavedNotification:
public void Handle(TemplateSavedNotification notification)
{
bool success = DoAdditionalCode();
if (success)
{
//on success
notification.Messages.Add(new EventMessage("Save Successful",
"The content was saved successfully",
EventMessageType.Success));
}
else
{
//on error
notification.Messages.Add(new EventMessage("An Error occoured",
"Detail about the error",
EventMessageType.Error));
}
}
Samples
Below you can find some articles with some examples using Notifications.
See for a list of the tree notifications.
See for a list of the EditorModel events.
Umbraco uses notifications to allow people to hook into different workflow processes. This notification pattern is extensible, allowing you to create and publish custom notifications, and other people to observe and hook into your custom processes. This approach can be useful when creating Umbraco packages. For more information on how you create and publish your own notifications, see the article.