Refactor reference priming and change callback signature

This PR moves reference priming out of DocumentPersister and into its own class. There is a BC break as the callback signature (for custom primers) has changed.

Related to #520.