IDocumentDeletedHandler

The IDocumentDeletedHandler is used in conjunction with the IDocumentHandler interface, to further specify that the handler should be executed before and after documents are deleted.

Interface declaration

public interface IDocumentDeletedHandler
{
	/// <summary>
	/// Is executed *before* a document is deleted
	/// </summary>
	/// <param name="document">The document which is going
	Task OnDeletingAsync(Document document);

	/// <summary>
	/// Is executed *after* a document has been deleted
	/// </summary>
	/// <param name="document">The document which was just
	Task OnDeletedAsync(Document document);
}

Example

In this example, we send an e-mail to a specific e-mail address everytime a document is deleted.

public class EmailNotificationsWhenDocumentsAreDeleted : IDocumentHandler, IDocumentDeletedHandler
{
    private readonly IEmailSenderService _emailSenderService;

    [EditorBrowsable]
    public string ToAddress { get; set; }

    public EmailNotificationsWhenDocumentsAreDeleted(IEmailSenderService emailSenderService)
    {
        _emailSenderService = emailSenderService;
    }

    public async Task OnDeletedAsync(Document document)
    {
        var body = $"¨Heads up! The document with the ID {document.Id} was just deleted!";
        _emailSenderService.SendMail(ToAddress, "Document deleted", body);
    }

    public async Task OnDeletingAsync(Document document)
    {
        // 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, EmailNotificationsWhenDocumentsAreDeleted>(ServiceLifetime.Transient);
}