This repository contains sample code and additional resources for the "C# Interfaces" course by Jeremy Clark on Pluralsight. The examples use .NET 5.0. Updated sample code will be posted after .NET 6 is released.
The code samples are in folders starting with the environment (net50), followed by the course module (module1). From there, the "before" and "after" folders contain the code at the beginning of the demo and the code at the end of the demo, respectively.
- C# Interfaces by Jeremy Clark (released Jun 2021)
To see what is new and changed from the previous course, please see ChangeLog.md.
The code samples can be followed using Visual Studio 2019 (Windows) or Visual Studio Code (Windows, Linux, macOS).
When using Visual Studio, open the solution file (.sln) that is included in each sample folder. The solution is set up to automatically start the web application as well as the required web service, so no special action is required.
Running the Web Service and Application
To run a project, click F5 or use "Start debugging" from the toolbar or Debug menu.
Your default browser will automatically open to http://localhost:5000 (the location of the web application). When you are done, close the browser window.
Running the Unit Tests
For the sample that has unit tests, open the Test Explorer in Visual Studio by selection "Test | Test Explorer" from the menu or "Ctrl+E, T".
In the Test Explorer, click the left-most button (or use "Ctrl+R, V") to run all of the tests.
When using Visual Studio Code, you will need to start the web service project separately from the web application.
Starting the Service
For the projects that have a "People.Service" folder, use the following steps to start the service:
- Open a terminal in the "People.Service" folder.
- Type "dotnet run". (This will rebuild the project if necessary.)
- The service should start and show the following info:
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:9874
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
If you open a browser to http://localhost:9874/people, you will see data from the service.
You can leave this terminal open for all of the samples; each sample uses the same web service.
To stop the service, press "Ctrl+C" in the terminal.
Running the Web Application
To run the web application (PeopleViewer), use the following steps:
- Open a terminal in the "PeopleViewer" folder.
- Type "dotnet run". (This will rebuild the project if necessary.)
- The web application should start and show the following info:
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
To run the application, open a browser to http://localhost:5000.
When you are done, you can stop the web server by going back to the terminal window and pressing "Ctrl+C".
Alternately, you can run the web application from within Visual Studio Code by using the integrated debugger. For more information, see Visual Studio Code - Debugging.
Running the Unit Tests
One of the samples includes unit testing. To run unit tests from the terminal, use the following steps:
- Open a terminal in the "PeopleViewer.Tests" folder.
- Type "dotnet test". (This will rebuild the project if necessary.)
- The tests will run and the result will be similar to the following:
Test run for ...\PeopleViewer.Test.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.9.4
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 2, Skipped: 0, Total: 2, Duration: 60 ms - PeopleViewer.Test.dll (net5.0)
For a listing of the relevant files in each sample project, please refer to the RelevantFiles.md file.
Downloads
- Visual Studio 2019 (Windows only)
Community Edition is free to use - .NET 5.0 (Windows, Linux, macOS)
- Visual Studio Code (Windows, Linux, macOS)
Article
- Patterns of Enterprise Application Architecture by Martin Fowler, et al.
- Dynamically Loading Types in .NET Core with a Custom Assembly Load Context by Jeremy Clark
- Getting Started with Dependency Injection in .NET Pluralsight course by Jeremy Clark
- Cross-Platform Build Events in .NET Core using MSBuild by Jeremy Clark
- A Closer Look at C# 8 Interfaces by Jeremy Clark
- C# 8 Interfaces: Properties and Default Implementation by Jeremy Clark
- C# 8 Interfaces: Public, Private, and Protected Members by Jeremy Clark
- C# 8 Interfaces: Static Members by Jeremy Clark
- Tutorial: Update interfaces with default interface methods in C# 8.0 Microsoft Docs
- Tutorial: Mix functionality in when creating classes using interfaces with default interface methods Microsoft Docs