Core

Registered Services

Strategie registrace služeb v DI. Provider-specific registrace a praktické příklady jsou rozdělené do podstránek.

Overview

Services are registered through service providers. Primary service IDs are class/interface names; selected modules also expose string aliases. Availability depends on enabled providers and app configuration.

Core services

Core bootstrap registers PSR-17/PSR-7 factories and runtime utilities via CoreServiceProvider, for example Psr17Factory, ResponseFactoryInterface, RequestFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface, ServerRequestFactory, ControllerResolver, BaseUrlResolver, FrameworkInfo, ExceptionLogger.

HTTP services

HttpServiceProvider (HTTP kernel only) registers middleware/runtime services such as ErrorHandlingMiddleware, RequestLoggingMiddleware, BenchmarkMiddleware, CorsMiddleware, PoweredByMiddleware, HtmlMinifyMiddleware, OptionsMiddleware, DispatchRequestHandler, MiddlewareResolver, MiddlewareStack, ErrorPageRenderer, HtmlMinifier, HttpRequestInspector, HttpLogContext.

Routing services

RoutingServiceProvider registers LocaleUrlStrategyInterface and UrlGenerator plus alias url. Router itself is bound earlier by Framework bootstrap.

Application services and aliases

Aliases exist only where providers register them. Typical aliases include url, validator, filesystem, files, directories, locks, translator, locale.resolver, csrf, session, flash, cache, cache.pool, log, log.app, log.benchmark, events, queue, psr17 and http.*Factory aliases.

Components

ComponentServiceProvider registers ComponentRegistry and built-in component keys breadcrumb, pagination, meta. Custom components are added via top-level config key components and resolved through ComponentRegistry::get(name, ExpectedClass::class).

Validation

ValidationServiceProvider registers RuleRegistry, FormValidation, alias validation.rules and alias validator.

Filesystem

FilesystemServiceProvider registers DirectoryManagerInterface, FileManagerInterface, LockManagerInterface, Filesystem and aliases filesystem, files, directories, locks.

Database

Database services come from DatabaseServiceProvider and driver providers. Core registrations include DatabaseConfig, ConnectionInterface, Database, DatabaseDriverInterface, SchemaGrammarInterface, SchemaCompiler, Schema. Concrete driver behavior depends on enabled driver providers and configured default connection.

Console and CLI

ConsoleServiceProvider registers CommandRegistry and is loaded by CliKernel only. CLI service availability differs from HTTP runtime because HttpServiceProvider is not part of CLI chain.

Optional modules

Additional providers register module-specific services: DebugServiceProvider (DumperInterface, alias dumper), EventServiceProvider (EventDispatcherInterface, alias events), QueueServiceProvider (QueueBusInterface, alias queue), UploadServiceProvider (UploadService, UploadFactory), BenchmarkServiceProvider (Benchmark, BenchmarkResponseInjector). HTTP client providers optionally bind Psr\Http\Client\ClientInterface.

Usage examples

Prefer constructor injection in application code. Use direct container access only where the container is explicitly available, especially inside provider factories. String aliases are provider service IDs, not a global runtime lookup mechanism.

// Constructor injection
public function __construct(
    private readonly UrlGenerator $url,
) {}

// Container access inside provider/factory
$container->singleton(LinkBuilder::class, static function (ContainerInterface $container): LinkBuilder {
    return new LinkBuilder(
        $container->get(UrlGenerator::class),
    );
});

Recommended app pattern

For application services, prefer explicit registration in app providers and constructor injection. Avoid service locator usage in action controllers and services; base controllers may use controller-scoped infrastructure access for context services only.

final class AppServiceProvider implements ServiceProviderInterface
{
    public function register(ContainerInterface $container): void
    {
        $container->singleton(App\Services\ArticlePageService::class, App\Services\ArticlePageService::class);
    }
}