Dependency injection support

Resending #1164