C#C
C#10mo ago
Vortac

Dependency Injection Question

I'm working on a music player which can play both local and streamed media. To play the files, I'm using a library which has a SoundPlayer class. (https://lsxprime.github.io/soundflow-docs/getting-started/)

To handle file vs streaming, I'm using a switch statement inside my SoundEngine class:
switch (fileType)
  {
    case eFileType.File:
      _player = new SoundPlayer(new StreamDataProvider(File.OpenRead((string)path)));
    break;
            
    case eFileType.Stream:
      _player = new SoundPlayer(new StreamDataProvider((Stream)path));
      break;

I shouldn't be newing up classes inside my SoundEngine, and want to use DI instead. However, since a user can play different files while the (which must be passed into the _player variable), I can't use constructor injection. Is there another way to handle this?
SoundFlow Documentation
Learn how to install the library, set up your development environment, and write your first SoundFlow application.
Was this page helpful?