IDocumentUpdatedHandler
The IDocumentUpdatedHandler is used in conjunction with the IDocumentHandler interface, to further specify that the handler should be executed before and after documents are updated.
Interface declaration
public interface IDocumentUpdatedHandler { /// <summary> /// Is executed *before* a document is updated. /// </summary> /// <param name="document">The document which is going to be updated</param> /// <param name="documentBeforeSave">The old version of the document, before Task OnUpdatingAsync(Document document, Document documentBeforeSave); /// <summary> /// Is executed *after* the document has been updated. /// </summary> /// <param name="document">The document which was just updated</param> /// <param name="documentBeforeSave">The old version of the document, before Task OnUpdatedAsync(Document document, Document documentBeforeSave); }
Example
In this example, we send an e-mail to the specified e-mail address when documents are updated. You have access to the document as it was before updating, in both methods. You could detect which fields where actually changed and include information about that in the e-mail as well.
public class EmailNotificationsWhenDocumentsAreUpdated : IDocumentHandler, IDocumentUpdatedHandler { private readonly IEmailSenderService _emailSenderService; [EditorBrowsable] public string ToAddress { get; set; } public EmailNotificationsWhenDocumentsAreUpdated(IEmailSenderService emailSenderService) { _emailSenderService = emailSenderService; } public async Task OnUpdatedAsync(Document document, Document documentBeforeSave) { var body = $"¨Heads up! The document with the ID {document.Id} was just updated!"; _emailSenderService.SendMail(ToAddress, "Document deleted", body); } public async Task OnUpdatingAsync(Document document, Document documentBeforeSave) { // Don't do anything before the document is deleted } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<IDocumentHandler, EmailNotificationsWhenDocumentsAreUpdated>(ServiceLifetime.Transient); }