No, that's not Dependency Injection.
Instead, consider injecting either the IAudioStream
dependency, or a factory thereof, into your client code.
public class AudioStreamClient
{
private readonly IAudioStream audioStream;
public AudiStreamClient(IAudioStream audioStream)
{
this.audioStream = audioStream;
}
public void DoStuff()
{
// use this.audioStream here...
}
}
Alternatively, if you need a new instance of IAudioStream
every time DoStuff
executes, consider injecting an Abstract Factory instead.
However, be mindful that this might be a Leaky Abstraction, and a better alternative is to create an Adapter that manages the object's lifetime for you.