# Unable to resolve service "HttpRouter" to a factory

**URL:** <https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654>\
**Category:** Migration\
**Tags:** zend-mvc, laminas-mvc\
**Created:** [March 29, 2024, 12:46pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654 "2024-03-29T12:46:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [March 29, 2024, 12:46pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/1 "2024-03-29T12:46:39Z")

</div>

Fatal error: Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service “HttpRouter” to a factory

There is two factory is missing. Router and HttpRouter. After adding this line into global.php

`'Router' => 'Laminas\Router\RouterFactory',` Router issue fixed but when I adding  
` ‘HttpRouter’ =\> ‘Laminas\Router\RouterFactory’, it going into infinite loop to getFactory method in ServiceManager.php

I found calling this `$serviceManager->get('Router')` but not finding where ‘HttpRouter’ is getting call. It should be called like `$serviceManager->get('HttpRouter');`

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [March 29, 2024, 3:52pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/2 "2024-03-29T15:52:31Z")

</div>

To answer your question, I can’t see your this page and what do you mean by this and that? I’ve no idea why you’re dumping the application object and what are you trying to prove.  
Laminas has not yet debunked legacy names of Zend Framework as it will create a massive backward compatibility issue. That is the reason why duplicate keys exist. It shows clearly you’ve no idea about the Zend Framework skeleton application and Laminas MVC skeleton application. I would suggest you first get a first-hand experience with it. Thanks!

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [March 29, 2024, 4:16pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/3 "2024-03-29T16:16:14Z")

</div>

Updated my question with more details after enabling xdebug.

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [March 29, 2024, 4:22pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/4 "2024-03-29T16:22:21Z")

</div>

The first thing to note when using a framework, you can’t change some specific keys and want to make it work as you wish. That is why there are some framework-specific keys you can’t change. Changing ‘Router’ with ‘HttpRouter’ with whose permission. Can I change your gender if I wish it?  
Why are you adding these keys in globa.php and how are you adding it? Adding any key anywhere will work in your opinion?  
The solution that I can give you is to disable modules one by one and make it equivalent to a Laminas Minimum framework requirement and then see what is the result. Then start enabling modules which are built by you or by your team.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [March 30, 2024, 2:50pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/5 "2024-03-30T14:50:07Z")

</div>

@Avinash_Dalvi not sure which version you are currently running but you may want to take a look here (latest version):

> <https://github.com/laminas/laminas-router/blob/54857573eeee4511d3287d56e22d01a0d809012a/src/ConfigProvider.php#L45>

There is aliases setup for ‘HttpRouter’, ‘router’ and ‘Router’ two of which point to the service identifier RouteStackInterface which is the identifier that points to the RouterFactory.

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [March 31, 2024, 7:54am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/6 "2024-03-31T07:54:24Z")

</div>

It is possible that he or his team may not have been working from the skeleton application. There is many ways to use Laminas libraries without starting with the MVC skeleton 😉

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [March 31, 2024, 10:44am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/7 "2024-03-31T10:44:47Z")

</div>

@Tyrsson, You’re showing a complete reference not just a line. Having an alias and the actual factory name is the same thing? Can I do the following? Also, he is in well-capable hands on the Slack channel.

```auto
'factories' => [
   'HttpRouter' => MyNamespace\Factory\MyAnonomusFactory::class,
];

class MyAnonoummusFactory extends ImaginaryFactory {
...
} 

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [March 31, 2024, 5:10pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/8 "2024-03-31T17:10:40Z")

</div>

Aliases should point to a service identifier or to another alias.

It’s not a “factory name” per-say. Its a service identifier. The service identifier should map to a factory that returns an instance of that service.

The general rule of thumb is that only core services with historically significant identifiers (ie ‘EventManager’) should use plain string identifiers. All other services should be mapped to class-string identifiers matching the service for which the factory returns an instance. We see why when using the FactoryInterface the $requestedName argument holds the requested service class-string, which is whatever was mapped to the factory. In your example above using the $requestedName to create an instance of the requested service would fail.

The real question for the OP is why is the default mappings not being read and used by the framework?

The thing to remember about slack is that those conversations have a maximum lifespan of 90 days. After that the information is lost to anyone that may find themselves having the same issues.

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [March 31, 2024, 5:13pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/9 "2024-03-31T17:13:42Z")

</div>

The root cause for the loop is due to mapping the HttpRouter to the RouterFactory instead of the HttpRouterFactory. You can not call an instance of the requested service from the container inside the factory that is supposed to create the service instance.

RouterFactory: (This line is causing the loop)

> <https://github.com/laminas/laminas-router/blob/5e55c60ac9bd88624025a86895551daaac6a01e6/src/RouterFactory.php#L29>

The root cause of your issues is that those mappings should already be provided by the MVC layer as far as I am aware. Of course this depends on which version of the components you are using. I’m not sure which version moved the configuration to Module.php/ConfigProvider.php classes.

It may help if you could tell us if you have a /config/modules.config.php file present in the tree?

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [April 1, 2024, 4:38am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/10 "2024-04-01T04:38:36Z")

</div>

“laminas/laminas-dependency-plugin”: “2.6.0”,  
“laminas/laminas-authentication”: “2.16.0”,  
“laminas/laminas-code”: “4.13.0”,  
“laminas/laminas-config”: “3.9.0”,  
“laminas/laminas-crypt”: “3.11.0”,  
“laminas/laminas-db”: “2.19.0”,  
“laminas/laminas-di”: “3.13.0”,  
“laminas/laminas-dom”: “2.14.0”,  
“laminas/laminas-eventmanager”: “3.13.0”,  
“laminas/laminas-feed”: “2.22.0”,  
“laminas/laminas-file”: “2.13.0”,  
“laminas/laminas-filter”: “2.34.0”,  
“laminas/laminas-form”: “3.19.2”,  
“laminas/laminas-http”: “2.19.0”,  
“laminas/laminas-i18n”: “2.26.0”,  
“laminas/laminas-inputfilter”: “2.30.0”,  
“laminas/laminas-json”: “3.6.0”,  
“laminas/laminas-ldap”: “2.18.1”,  
“laminas/laminas-loader”: “2.10.0”,  
“laminas/laminas-log”: “2.17.0”,  
“laminas/laminas-mail”: “2.25.1”,  
“laminas/laminas-math”: “3.7.0”,  
“laminas/laminas-memory”: “2.11.0”,  
“laminas/laminas-mime”: “2.12.0”,  
“laminas/laminas-modulemanager”: “2.15.0”,  
“laminas/laminas-mvc”: “3.7.0”,  
“laminas/laminas-navigation”: “2.19.1”,  
“laminas/laminas-paginator”: “2.18.1”,  
“laminas/laminas-permissions-acl”: “2.16.0”,  
“laminas/laminas-permissions-rbac”: “3.6.0”,  
“laminas/laminas-progressbar”: “2.13.0”,  
“laminas/laminas-serializer”: “2.17.0”,  
“laminas/laminas-server”: “2.17.0”,  
“laminas/laminas-servicemanager”: “^3.11.2”,  
“laminas/laminas-session”: “2.20.0”,  
“laminas/laminas-soap”: “2.13.0”,  
“laminas/laminas-stdlib”: “3.19.0”,  
“laminas/laminas-tag”: “2.11.0”,  
“laminas/laminas-test”: “4.10.0”,  
“laminas/laminas-text”: “2.11.0”,  
“laminas/laminas-uri”: “2.11.0”,  
“laminas/laminas-validator”: “2.52.0”,  
“ocramius/package-versions”: “2.8.0”,  
“laminas/laminas-xmlrpc”: “2.19.0”,  
“laminas/laminas-view”: “2.34.0”,  
“laminas/laminas-router”: “^3.13”

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [April 1, 2024, 4:49am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/11 "2024-04-01T04:49:52Z")

</div>

> [@Tyrsson](#):
>
> RouterFactory

I am using modules.config.php under /modules/Application/config/module.config.php

 ![Screenshot 2024-04-01 at 10.19.42 AM](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/3/39f3e4ec3f6a38b66fe0ebe142b0f5f082051b55.png)

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [April 1, 2024, 5:18am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/12 "2024-04-01T05:18:52Z")

</div>

Issue got resolved after adding  
`'HttpRouter' => 'Laminas\Router\Http\HttpRouterFactory',`  
Thanks all for help.

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [April 1, 2024, 5:27am UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/13 "2024-04-01T05:27:35Z")

</div>

Just to summarised this issue. Allowed memory size got exhausted because one factory was calling under infinite loop.

How I found issue ? After enabling Xdebug i got to know exact error otherwise it was just showing “This page isn’t working” which is standard one. If you want to know exact issue xdebug is good tool to find out root cause.

How I solved issue ?

There was two factory was not able to load because missing configuration for factories. Which was Router and HttpRouter. To solve that I added below lines which was there in my old code before upgrading laminas.

```auto
'Router' => 'Laminas\Router\Http\RouterFactory',

'HttpRouter' => 'Laminas\Router\Http\RouterFactory',

```

But actual issue was [laminas-router/src/RouterFactory.php at 5e55c60ac9bd88624025a86895551daaac6a01e6 · laminas/laminas-router · GitHub](https://github.com/laminas/laminas-router/blob/5e55c60ac9bd88624025a86895551daaac6a01e6/src/RouterFactory.php#L29) this line was calling again HttpRouter, it become infinite loop. like h Router is pointing to HttpRouter in this file but in factories I was pointing to HttpRouter.

I solved this to finding right factory.

```auto
'Router' => 'Laminas\Router\RouterFactory',

'HttpRouter' => 'Laminas\Router\Http\HttpRouterFactory',

```

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [April 1, 2024, 12:54pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/14 "2024-04-01T12:54:46Z")

</div>

> [@Avinash\_Dalvi](#):
>
> There was two factory was not able to load because missing configuration for factories. Which was Router and HttpRouter. To solve that I added below lines which was there in my old code before upgrading laminas.

These factories are provided by the component and the component autowires them. The important question that needs to be answered is why your application is not reading the default configuration. My guess is that you are not using the laminas component installer and therefore they are not being added to the /config/modules.config.php file.

You may want to read this:

> **[laminas-component-installer - Laminas Docs](https://docs.laminas.dev/laminas-component-installer/)**
>
> Composer plugin for injecting modules and configuration providers into application configuration

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 1, 2024, 4:14pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/15 "2024-04-01T16:14:15Z")

</div>

> [@Tyrsson](#):
>
> The important question that needs to be answered is why your application is not reading the default configuration.

Something is absolutely wrong here, nothing needs to be configured manually because everything is already there. 🤷🏻‍♂️

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [April 1, 2024, 4:16pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/16 "2024-04-01T16:16:22Z")

</div>

I’ve tracked it down to their Module files are not being read. They are in the middle of a migration and do not have a /config/application.config.php / /config/modules.config.php file present. Which means, as we know, the autowiring is not being read.

---

<div class="post-metadata">

**Author:** ![Avinash\_Dalvi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/avinash_dalvi/32/1687_2.png) [@Avinash\_Dalvi](https://discourse.laminas.dev/u/Avinash_Dalvi)\
**Post date:** [April 1, 2024, 5:31pm UTC](https://discourse.laminas.dev/t/unable-to-resolve-service-httprouter-to-a-factory/3654/17 "2024-04-01T17:31:19Z")

</div>

Thanks for suggestion. I Moved changes to application.config.php for missing modules and its works.
