# How to create resourceGenerator - Expressive HAL

**URL:** <https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444>\
**Category:** Mezzio\
**Tags:** expressive, zend-expressive-hal\
**Created:** [January 24, 2018, 10:52am UTC](https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444 "2018-01-24T10:52:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelB](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@MichaelB](https://discourse.laminas.dev/u/MichaelB)\
**Post date:** [January 24, 2018, 10:52am UTC](https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444/1 "2018-01-24T10:52:22Z")

</div>

Hi,

I try to use zend-expressive-hal like in the documentation ([https://docs.zendframework.com/zend-expressive-hal/intro/](https://docs.zendframework.com/zend-expressive-hal/intro/)) 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?

---

<div class="post-metadata">

**Author:** ![MichaelB](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@MichaelB](https://discourse.laminas.dev/u/MichaelB)\
**Post date:** [January 24, 2018, 3:35pm UTC](https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444/2 "2018-01-24T15:35:58Z")

</div>

I answer to my self… 😉

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
            ...
        ],
    ];
}
```

---

<div class="post-metadata">

**Author:** ![matthew](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/matthew/32/14_2.png) [@matthew](https://discourse.laminas.dev/u/matthew)\
**Post date:** [January 24, 2018, 3:45pm UTC](https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444/3 "2018-01-24T15:45:39Z")

</div>

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:

```php
$aggregator = new ConfigAggregator([
    // Add it here:
    \Zend\Expressive\Hal\ConfigProvider::class,

```

---

<div class="post-metadata">

**Author:** ![MichaelB](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@MichaelB](https://discourse.laminas.dev/u/MichaelB)\
**Post date:** [January 25, 2018, 1:25pm UTC](https://discourse.laminas.dev/t/how-to-create-resourcegenerator-expressive-hal/444/4 "2018-01-25T13:25:25Z")

</div>

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.
