DefinitionInterface#

Georgeff\Kernel\DI\DefinitionInterface

A fluent builder returned by KernelInterface::define(). Configures how a service is stored, aliased, and tagged.

Methods#

public function share(): static;

Makes the service a singleton. The factory is called once; subsequent resolutions return the cached instance.

public function alias(string $alias): static;

Registers an additional ID that resolves to the same service. Can be called multiple times.

public function tag(string $tag): static;

Adds a tag to this service. Can be called multiple times. Tagged services can be retrieved together via TagRegistryInterface::getTagged() .

Accessor methods#

public static function for(string $id, callable $factory): static;

Static factory. Normally not called directly — use KernelInterface::define() instead.

public function getId(): string;
public function getFactory(): callable;
public function isShared(): bool;
public function getAliases(): string[];
public function getTags(): string[];

Example#

$kernel->define(CacheInterface::class, fn($c) => new RedisCache(
    $c->get(RedisConnection::class)
))
->share()
->alias('cache')
->tag('resettable');