Change routing table dispatcher to handle opt outs

At the moment, we rely on an opt out middleware attached to the routing table dispatcher for this. The plan is to move this handling onto the routing table dispatcher. This will help make #1127 possible.
We should probably leave the middleware in for a while (although deprecate it and maybe rewrite it to use the new helper) to avoid breakage if the code gets deployed without the corresponding config changes.

It should be safe to apply it more than once, right?