Listeners: What are delete listeners and how to work with them?

IDocumentDeleteListener interface which needs to be implemented if a user wants to add a custom logic or an action when a delete operation is executed. The interface contains only one method that is invoked before the delete request is sent to the server:

public interface IDocumentDeleteListener
{
	/// <summary>
	/// Invoked before the delete request is sent to the server.
	/// </summary>
	/// <param name="key">The key.</param>
	/// <param name="entityInstance">The entity instance.</param>
	/// <param name="metadata">The metadata.</param>
	void BeforeDelete(string key, object entityInstance, RavenJObject metadata);
}

Example

To prevent anyone from deleting documents we can create PreventDeleteListener with can be implemented as follows:

public class PreventDeleteListener : IDocumentDeleteListener
{
	public void BeforeDelete(string key, object entityInstance, RavenJObject metadata)
	{
		throw new NotSupportedException();
	}
}