Replace direct usage of container with dependency injection