容器与依赖注入
Mtphp\Container 提供 bind(原型)、singleton(单例)、instance(直接注册)与 make(解析)。构造器反射结果按类缓存,避免重复反射。
$app->container()->bind('cache', fn () => new RedisCache());
$app->container()->singleton(App\Services\UserService::class, fn () => new UserService());
$svc = $app->container()->make(App\Services\UserService::class); // 自动递归解析依赖
控制器方法参数按类型由容器解析(见第 7 节)。