Make Rewrite layer pluggable

Initial review draft. Adding Tests for new code are still pending. Am working on them Existing tests are passing.
Does this class have to be a singleton? I think this can be contained in LensServices instance.