Skip to content
Last update: August 24, 2024

Extend Notification Types

Sometimes you might need to extend the existing notification type with new properties, or override the existing default template with some new ones.

To extend the existing notification, for example, SampleEmailNotification:

  1. Create a new notification class based on the notification type you want to extend:

    public class ExtendedSampleEmailNotification : SampleEmailNotification
    {
        public ExtendedSampleEmailNotification() : base(nameof(ExtendedSampleEmailNotification))
        {
        }
    }
    
  2. Add the following line into the Module.cs file:

    Module.cs
    public void PostInitialize(IApplicationBuilder appBuilder)
    {
    ...
    var registrar = appBuilder.ApplicationServices.GetService<INotificationRegistrar>();
    registrar.OverrideNotificationType<SampleEmailNotification, ExtendedSampleEmailNotification>()
            .WithTemplates(new EmailNotificationTemplate()
            {
                Subject = "Extended SampleEmailNotification subject",
                Body = "Extended SampleEmailNotification body test"
            });
    ...
    }
    

Note

Running the .WithTemplates(new EmailNotificationTemplate() extension method is optional and can be used in case you want to override the default templates.