# When do I need FactoryInterfaces?

**URL:** <https://discourse.laminas.dev/t/when-do-i-need-factoryinterfaces/2131>\
**Category:** Mezzio\
**Created:** [February 25, 2021, 12:51pm UTC](https://discourse.laminas.dev/t/when-do-i-need-factoryinterfaces/2131 "2021-02-25T12:51:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hjerti](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@hjerti](https://discourse.laminas.dev/u/hjerti)\
**Post date:** [February 25, 2021, 12:51pm UTC](https://discourse.laminas.dev/t/when-do-i-need-factoryinterfaces/2131/1 "2021-02-25T12:51:45Z")

</div>

Hey there,

I have a question, I am learning mezzio and programming in general for no long time. So I had the task to create some factorys in my code. A co-worker showed me how and one time he implemented the FactoryInterface and one time he doesn’t. Do I have to use the FactoryInterface for every Factory? Because I did not use it in every Factory and it works. I could not figure out, for what exactly I need the FactoryInterface and for what not.

Can somebody explain it to me?

kind regards,  
hjerti

---

<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:** [February 25, 2021, 1:10pm UTC](https://discourse.laminas.dev/t/when-do-i-need-factoryinterfaces/2131/2 "2021-02-25T13:10:55Z")

</div>

Hello and welcome to our forums! 😃

> [@hjerti](#):
>
> Do I have to use the FactoryInterface for every Factory?

If you mean `Laminas\ServiceManager\Factory\FactoryInterface` then no. There are two reason:

1. The interface comes with laminas-servicemanager but [you can use other dependency injection containers](https://docs.mezzio.dev/mezzio/v3/features/container/intro/). This means that the interface is not always available.
2. [A factory does not have to be a class.](https://docs.mezzio.dev/mezzio/v3/features/container/config/#factories)

---

<div class="post-metadata">

**Author:** ![hjerti](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@hjerti](https://discourse.laminas.dev/u/hjerti)\
**Post date:** [February 25, 2021, 1:17pm UTC](https://discourse.laminas.dev/t/when-do-i-need-factoryinterfaces/2131/3 "2021-02-25T13:17:04Z")

</div>

thank you for the welcome!  
I think that helps, thanks 🙂
