I have a bunch of step definition classes that I would like to inject a shared client in.
class FirstStepDefinition {
private final Client client;
public FirstStepDefinition(Client client) {
this.client = client;
}
}
I don’t own Client
class and it does not have a default constructor. So how do I store construct the Client
instance with an argument inside pico container to be injected elsewhere?
public Client client() {
return Client("api-key");
}
You can extend Client
class (unless it is final
one) that would have default constructor calling super("api-key")
.
Due to polymorphism you will be able to use this class wherever original Client
is required.