Use a key function instead of having repositories return maps

cc @fwbrasil 

Maybe there is a more elegant way to provide the key function