Injecting ResponseInterface to Container

I can successfully place the RouteParserInterface in the container and use it in my base controller which is extended by other controllers.

$app = AppFactory::create();

$routeParser = $app->getRouteCollector()->getRouteParser();

$container->set(Slim\Interfaces\RouteParserInterface::class, $routeParser);

On the same way, I want to place the ResponseInterface in the container and use it in my base controller to create some utility methods. Any help on this?

Thanks in advance.

The request and response objects are context specific and should not be created or stored within the DI-Container because Slim itself is responsible to create and pass these objects through the HTTP request cycle.

If you need some http utility methods, I would recommend implementing those classes and using Dependency Injection where it is needed. Example

1 Like

Thanks. It was useful for my understanding.