ServiceProviderInterface

Hi,
A ideia for slim4:
Should slim4 have a ServiceProviderInterface for registering services in the container?

A ServiceProvider would serve the pourpose to register services in the container and boot them up and unlike middleware is not intended to change the response neither is dependent on the request.

namespace Slim\Interfaces;

interface ServiceProviderInterface
{
public static function register();
public static function boot();
}

We should have a way to register a provider globally for a single route or a route group just like the middleware

// register globally (for all routes)

$app->register(new \App\ServiceProviders\ProviderA);

// register for a single route

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $response->getBody()->write("Hello, $name");

    return $response;
})->register(new \MyApp\ServiceProviders\ProviderA);

// register for a route group

$app->group('', function() {
    $this->get('/billing', function ($request, $response, $args) {
        // Route for /billing
    });
    $this->get('/invoice/{id:[0-9]+}', function ($request, $response, $args) {
        // Route for /invoice/{id:[0-9]+}
    });
})->register(new \MyApp\ServiceProviders\ProviderA);

thanks.

I am not sure what you are saying here. But Slim 4 will not include a container by default, you will be free to add your own as you see fit.

Hi, I came here because I am researching how to implement the service provider pattern in slim. I have even seen $app->register() in the wild (https://github.com/alhoqbani/slim-php-realworld-example-app) and so I am just very confused. There seems to be features that aren’t documented, but sometimes when I try them they don’t work. Must be something that was taken out of the framework in the past? Now you are saying slim 4 won’t contain a container? uhhh…what will be left? Seems like a fairly “breaking” change to me? I don’t want to be insulting in any way but I’m not 100% sure what the point of slim will be if you strip that out. At that point it will just be a router and there are probably better routers in existence so what am I missing?