Major configuration and DI refactorings.

Extracted DI and CLI configuration into a separate lib.