Skip to content

Integration Application Event Handler

Phil Oyston edited this page Jul 25, 2016 · 9 revisions

When Umbraco starts it scans all the available assemblies for classes derived from ApplicationEventHandler. Umbraco.Elasticsearch has a SearchApplicationEventHandler that must be derived from within your application. This class will tell Umbraco.Elasticsearch how and where to index your content, in addition Umbraco.Elasticsearch will attach itself to a number of Umbraco events to ensure it is notified of important activities within the CMS.

  • Content Published/Unpublished/Trashed
  • Media Saved/Deleted

These events will trigger Elasticsearch indexing actions for configured content and media types.

You create a new class and derive it from the SearchApplictionEventHandler, where you will be required to implement a number of methods that describe:

public class UmbracoElasticsearchStartup : SearchApplicationEventHandler
{
  protected override IElasticsearchIndexCreationStrategy GetIndexCreationStrategy(IElasticClient client)
  {
    return new UmbracoElasticsearchIndexCreationStrategy(client);
  }

  protected override IEnumerable<IContentIndexService> RegisterContentIndexingServices()
  {
    yield return new ArticleContentIndexService();
  }

  protected override IEnumerable<IMediaIndexService> RegisterMediaIndexingServices()
  {
    return Enumerable.Empty<IMediaIndexService>();
  }
}