DI Cheat Sheet#
Quick reference for the current InterMix DI API.
Container Entry Points#
Action |
API |
|---|---|
Create/get instance |
|
Get manager |
|
Resolve by ID/class |
|
Resolve + execute default/registered method |
|
Build class (optional method) |
|
Call closure/function/class/method |
|
Scopes |
|
Tags / tracing / graph |
|
Freeze config |
|
Managers At A Glance#
Manager |
Core methods |
|---|---|
|
|
|
|
|
|
|
|
All managers use ManagerProxy: $mgr('id'), $mgr->id, $mgr['id'], proxied container methods and ->end() to return to the container.
Task Matrix (Fluent vs Shortcut)#
Task |
Fluent chain |
Shortcut on container |
|---|---|---|
Bind definition |
|
|
Register constructor map |
|
|
Set options |
|
|
Resolve service |
|
|
Resolve return value |
|
|
Call target |
|
|
Build target |
|
|
Common Recipes#
Bootstrap chain:
$c->definitions()
->bind(LoggerInterface::class, FileLogger::class)
->registration()
->registerClass(App::class, ['name' => 'InterMix'])
->options()
->setOptions(injection: true, methodAttributes: true)
->enableLazyLoading(true)
->end();
Environment-specific binding + metadata:
use Infocyph\InterMix\DI\Support\LifetimeEnum;
$c->options()
->bindInterfaceForEnv('prod', MailerInterface::class, SmtpMailer::class)
->bindInterfaceForEnv('test', MailerInterface::class, FakeMailer::class)
->setDefinitionMetaForEnv('test', 'mailer', LifetimeEnum::Transient, ['core', 'test-only'])
->setEnvironment('test');
Definition cache warmup:
$c->definitions()
->enableDefinitionCache($pool)
->cacheAllDefinitions(forceClearFirst: true);
Scoped resolution:
$result = $c->withinScope('request-42', function () use ($c) {
return $c->get(RequestContext::class);
});
Advanced Helpers#
$c->parseCallable($spec): normalize closure/function/class/method input (class-method targets must be autoloadable and exist).$c->resolveNow(...): resolve with explicit runtime knobs.$c->getRepository(): inspect low-level runtime state.$c->setResolverClass(FooResolver::class): swap resolver implementation.
See also: Quick-Start, Definition Manager API, Registration Manager, Options & Feature Toggles, Invocation & Shortcuts, Scopes, Environment‑specific bindings, Debug Tracing