Let's look at an example

So, let's see an example that violates the dependency principle, propose a solution, and see how that solution might take several flavors depending on the application's needs (or even the programmer's tastes, in many situations).

We're going to use a basic .NET app to settle the initial scenario. It's just a classic console application that reads a file with a movie's information from a specific directory, and presents the content in the console.

We'll start with a file called MovieDB.xml (in the XML format and stored in the app's data subdirectory) with a data structure like the following:

    <Movie>
      <ID>1</ID>
      <Title>Jurassic Park</Title>
      <OscarNominations>3</OscarNominations>
      <OscarWins>3</OscarWins>
    </Movie> 

Get Dependency Injection in .NET Core 2.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.