Finally implement dependency injection for classes that need it

#419 will be grouped into the same MR as this issue.