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.