Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Decide on if the service wrapper should return a shared instance or new instances #1

Open
swichers opened this issue Sep 28, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@swichers
Copy link
Owner

Given:

$container->setParameter('acsf.client.connection', ['environment' => 'live'] +
  $base_config);
$live_client = $container->get('acsf.client');

$container->setParameter('acsf.client.connection', ['environment' => 'uat'] +
  $base_config);
$uat_client = $container->get('acsf.client');
print_r($uat_client->getConfig());

$uat_client will still contain the original configuration. This is because services are shared by default with Symfony: https://symfony.com/doc/current/service_container/shared.html

It's easy enough to change configuration after the client has been requested:

$container->setParameter('acsf.client.connection', ['environment' => 'live'] +
  $base_config);
$client = $container->get('acsf.client');
$client->setConfig(['environment' => 'uat'] + $client->getConfig());

This makes difficult to work with two separate clients at once. It also may pose problems in the future if something changes around the config system.

It can be mitigated by manually creating the Client object without using the service. It would be helpful to have a client factory service that could spin of instances per environment.

@swichers swichers added the enhancement New feature or request label Sep 28, 2019
@swichers swichers changed the title Unable to get different clients using the service wrapper Decide on if the service wrapper should return a shared instance or new instances Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant