11

The title says it all: what is a hook and how does it differ from a pipeline processor?

Specifically, I am looking for the following:

  • What is a hook?
  • How/when are hooks triggered?
  • What are hooks used for?
  • How do hooks differ from pipeline processors?
  • I can only guess that the downvotes have been due to the content length of the question, so I added some more specific details that i'm looking for. If there is something else wrong with the question, please let me know so that I can fix it :) – Zachary Kniebel Oct 26 '16 at 19:01
13

Hooks

A hook is a mechanism that you can use to run or "register" some logic at initialization time. To create one, you implement the IHook interface and add the necessary configuration as determined by your implemented hook. Hooks are loaded and executed when the application is initialized, via the Sitecore.Pipelines.Loader.LoadHooks processor of the <initialize> pipeline.

Hooks are typically used for situations when you have some initialization-time logic that needs to be run but doesn't really belong within the <initialize> pipeline and doesn't depend on a context. For example, Sitecore uses hooks OOTB for health monitoring and memory checking.

Hooks are especially useful when you have a recurring task that you want to set up to run on a time interval. For example, if you want to ping a service on a set time interval and you do not require any site or item context then a Hook may be what you need.

Mike Reynolds has a great blog post describing what a hook is and how you can implement one, and I highly recommend it for additional details.

Hooks vs. Pipeline Processors

Remember that Hooks are loaded and executed in the <initialize> pipeline, but they are not processors. Hooks don't require any Sitecore context, and they do not have any arguments. As such, hooks are lighter-weight than processors and thus better suited for smaller tasks that don't depend on a context.

This blog post by John West is a good resource for additional information on the differences between a Hook and a Pipeline Processor.

| improve this answer | |
  • 2
    Further, since all the hooks are executed through a single processor, it's quite easy to disable the entire set in one fell swoop. I suspect this is just some legacy functionality that has been superseded by the <initialize /> pipeline. Can anyone confirm that suspicion? – Richard Hauer Oct 27 '16 at 11:34
  • That is true. You can disable the processor – Zachary Kniebel Oct 27 '16 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.