I have a class which uses the Azure SDK. The class has two constructors, shown in pseudo code below:
public StephensWorkerClass(){
this.azureClient = await getNewAzureClient();
} //normally used
//just for testing
public StephensWorkerClass(IAzure azureClient){
this.azureClient = azureClient;
}
In normal usage, the empty constructor will be called and the constructor will do what needs to be done to make a new IAzure for us to use internally within the method.
To allow for unit testing, I made the second constructor which can recieved a Moq'd IAzure instance, and in my Unit tests, this works great.
My question though, is this an anti-pattern? If so, what's the way out from here? I was thinking I could make this method accept a nullable IAzure and if null, then call the method to new up a new IAzure client. Any tips?