Before we get into ASP.NET, let’s take a look at a basic dependency in C#.

In this program we have two important classes:

  • Trainer
  • LoudSpeaker

In order to work correctly, the Trainer class needs a LoudSpeaker instance. Thus LoudSpeaker will be a dependency for the Trainer class.



In Trainer.cs, in the Trainer constructor, instantiate a LoudSpeaker object and store it in the speaker field.

You instantiate LoudSpeaker with the parameterless constructor:

new LoudSpeaker()

In the body of Trainer.BeginTraining(), use the speaker by adding this line:

speaker.Amplify("Time to sweat");

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?