Dependency injection support. Resolves #1115

I hope this will help with organizing of tests.