Fixes #4957: Adds service provider based on DI container

This replaces #466, rebased for master. All tests passing