Refactor how contexts are created and passed to component instances.