© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
51 replies
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
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;
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
Getting Started with SoundFlow
Learn how to install the library, set up your development environment, and write your first SoundFlow application.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dependency Injection question
C#CC# / help
17mo ago
✅ Dependency Injection question
C#CC# / help
3y ago
Question about Dependency Injection:
C#CC# / help
13mo ago
Dependency injection questions
C#CC# / help
4y ago
Next page