Changes to support derived account models, custom key types and non-ef repositories

Implementation details are here:

https://gist.github.com/Roysvork/6d3ad44bbfeb8458c11c