# Config service with shared data on multiple instances

**URL:** <https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940>\
**Category:** Components & MVC\
**Created:** [February 11, 2019, 9:28pm UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940 "2019-02-11T21:28:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaclav\_Vanik](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/vaclav_vanik/32/539_2.png) [@Vaclav\_Vanik](https://discourse.laminas.dev/u/Vaclav_Vanik)\
**Post date:** [February 11, 2019, 9:28pm UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940/1 "2019-02-11T21:28:48Z")

</div>

I have Expressive application running on multiple servers (on each server is one instance). I would like to have an ability of changing (overriding) some options in container config service in my application gui.

I really dont know how to solve this.

I cant create delegator factory - because config is a service  
I cant create config aggregator provider - because service container is not built

Help is really appreciated 🙂

---

<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:** [February 11, 2019, 9:30pm UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940/2 "2019-02-11T21:30:52Z")

</div>

I suggest setting environment variables in each server, and then accessing them via `getenv()` within your configuration files. This will work for any scalar option you have.

---

<div class="post-metadata">

**Author:** ![Vaclav\_Vanik](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/vaclav_vanik/32/539_2.png) [@Vaclav\_Vanik](https://discourse.laminas.dev/u/Vaclav_Vanik)\
**Post date:** [February 11, 2019, 10:32pm UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940/3 "2019-02-11T22:32:02Z")

</div>

I should be more precise in my question. Use case:  
My application creates invoices. Default seller info is in config service.  
These info is then injected to invoice generator in factory.

```auto
$config = [ // default config
    'seller_name' => 'My company ltd.',
    'seller_street' => 'Street 666',
];

InvoiceGeneratorFactory
{
    public function __invoke(ContainerInterface $config)
   {
        $config = $container->get('config');
        return InvoiceGenerator($config['seller_name'], /* ....*/);
   }
}

```

Well… and I would like to create seller info form which can than override default seller info provided by config service.

---

<div class="post-metadata">

**Author:** ![guidofaecke](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/guidofaecke/32/427_2.png) [@guidofaecke](https://discourse.laminas.dev/u/guidofaecke)\
**Post date:** [February 12, 2019, 4:36am UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940/4 "2019-02-12T04:36:50Z")

</div>

Something like this?

```auto
class InvoiceGeneratorFactory
{
    public function __invoke(ContainerInterface $container)
    {
        $config = $container->get('config');

        return InvoiceGenerator($config['seller_name'], /* ....*/);
   }
}

```

```auto
class InvoiceGenerator
{
    /** @var string */
    private $sellerName;

    public function __construct(string $sellerName, /* .... */)
    {
        $this->sellerName = $sellerName;
    }

    public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler
    ) : ResponseInterface {
        $query = $request->getQueryParams();
        
        $sellerName = $query['seller_name'] ?? $this->sellerName);

        /* generate invoice .... */
    }
}

```

---

<div class="post-metadata">

**Author:** ![vlx](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vlx](https://discourse.laminas.dev/u/vlx)\
**Post date:** [February 18, 2019, 7:30am UTC](https://discourse.laminas.dev/t/config-service-with-shared-data-on-multiple-instances/940/5 "2019-02-18T07:30:25Z")

</div>

I think config shall be used for immutable or default values only. Why not go for setter method? InvoiceGenerator is obviously not a value object, so why would you not want to have a setter for seller?
