@vincent15000 A service container is a central location where services are bound. An application should only have one container. You wouldn’t create “new” containers for a module; you’d instead have service providers in each module that adds that specific module’s services to the application’s service container.
As for performance, you can create “deferrable” service providers that only resolve services if they’re actually requested during a request:
class FooServiceProvider extends ServiceProvider implement DeferrableProvider
{
public function register()
{
$this->app->singleton(FooService::class, function () {
return new FooService();
});
}
public function provides()
{
return [
FooService::class,
];
}
}
The provides method indicates what services the service provider actually provides. So the callback for the FooService will only be executed if FooService is actually requested.