What makes more sense regarding dependency injecti...
# general-advice
j
What makes more sense regarding dependency injection? Making the object and passing it on, or passing the parameters so the dependent service can make the object? In this example I’m making a service that relies on an external api (not limited to that, could be a database for example). The url and token would come from a config file
Copy code
private val apiClient = APIClient(apiUrl, apiToken)
    private val someService(apiClient)         // option 1
    private val someService(apiUrl, apiToken). // option 2
r
I like option 1, as it lets me inject a different implementation of
APIClient
. You can always provide both.