You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Listeners: What are listeners?

The concept of listeners provides users with a mechanism to perform custom actions, in response to operations taken in a session. The listener implements an interface whose methods are called when a particular action is executed on an entity or querying is run.

There are five types of available listeners:

  • Document Conflict listeners (IDocumentConflictListener),
  • Document Conversion listeners (IDocumentConversionListener)
  • Document Delete listeners (IDocumentDeleteListener)
  • Document Store listeners (IDocumentStoreListener)
  • Document Query listeners (IDocumentQueryListener)

In order to add new listener you must register it in DocumentStore:

store.RegisterListener(new SampleDocumentStoreListener());

You can also set all your listeners at once by the following method:

store.SetListeners(new DocumentSessionListeners()
{
	StoreListeners = new IDocumentStoreListener[]
	{
		new SampleDocumentStoreListener()
	},
	DeleteListeners = new IDocumentDeleteListener[]
	{
		new SampleDocumentDeleteListener()
	}
});