Closed tanigami closed 2 years ago
There isn't a great cost to just instantiating a new Client though, at which point your problem is solved without DI.
You can keep connections open in a pool (which you'd create to receive ShopifyClient
instances), making everything you've changed less useful.
Problem
if you wanna inject the dependency of
ShopifyClient
into some class from a DI container and you need to set$accessToken
and a$shopName
dynamically according to situations, you will want to set them after instantiation, but it's not easy becauseShopifyClient
first requires them as constructor arguments.Approach
Stop requiring those constructor arguments and add some guard to avoid forgetting to set
$accessToken
and$shopName
while allowing constructor arguments as it is.By the way, the class above can be tested like below for instance:
@rodolfobandeira @joshubrown Hope this change make sense. 😃