How to create resourceGenerator - Expressive HAL


I try to use zend-expressive-hal like in the documentation ( but something is not clear for me.

$resourceGenerator, $responseFactory, … are injected in the Action middleware.

class BookAction implements ServerMiddlewareInterface

public function __construct(
    Repository $repository,
    ResourceGenerator $resourceGenerator,
    HalResponseFactory $responseFactory
) {
    $this->repository = $repository;
    $this->resourceGenerator = $resourceGenerator;
    $this->responseFactory = $responseFactory;


But how can i generate the $resourceGenerator and $responseFactory in my Action middleware factory ?? With which value? Is it the right place?

class BookFactory
public function __invoke(ContainerInterface $container)
$repository = $container->get(BookTable::class);

    $responseFactory = ???
    $resourceGenerator = ???

    return new BookAction($repository, $responseFactory, $resourceGenerator);


I already create a MetadataMap::class in the config.

Someone can help me?

I answer to my self… :wink:

In Action Factory retrieve class like that:

    $responseFactory = $container->get(HalResponseFactory::class);
    $resourceGenerator = $container->get(ResourceGenerator::class);

And add in configProvider:

public function getDependencies()
    return [

        'factories'  => [
            Zend\Expressive\Hal\ResourceGenerator::class => Zend\Expressive\Hal\ResourceGeneratorFactory::class,
            Zend\Expressive\Hal\HalResponseFactory::class => Zend\Expressive\Hal\HalResponseFactoryFactory::class

If you are using Expressive, and have the zend-component-installer plugin as a development dependency (it’s enabled by default in the skeleton), you should get prompted when adding zend-expressive-hal to your application to add it to your config/config.php file; if you selected “yes”, these factories will be registered for you already.

If you didn’t select “yes”, then you can add the zend-expressive-hal ConfigProvider manually to your config/config.php file:

$aggregator = new ConfigAggregator([
    // Add it here:

Thanks @matthew, our posts have crossed. I found my problem. I had to register 2 factories (HAL) in my config, like in my second post.