Use dependency injection for factory for client

Better to use dependency injection where the factory class is needed,
rather than making the factory class a singleton. This makes everything
more flexible and testable.