public function extend($name, callable $extender)
    {
        if (! isset($this->factories[$name])) {
            throw new Exception(
                'Trying to extend unknown resource "' . $name . '"',
                Exception::RESOURCE_NAME_UNKNOWN
            );
        }
        $factory = $this->factories[$name];
        $this->factories[$name] = $this->share(
            function ($container) use ($extender, $factory) {
                return $extender($factory, $container);
            }
        );
    }