- Home
- .NET code examples
- Dependency injection in ASP.NET Core
Dependency injection in ASP.NET Core
ASP.NET Core implements the dependency injection (DI) design pattern.
Time property is declared with these services and the current time is set when each service is initialised.
Time property's value from the controller and view, and output it to the view to see the comparison.
Software
This is the software that will need to be installed onto your machine.
- Visual Studio 2019. Version 16.8.4 or above (may work with lower versions). It will work with the free community version.
- .NET 5.0 SDK, or above.
Get The Application Working
These are the steps to get the application working.
- Fill out the code example form. We will send you an email where you can download the code example.
You are now ready to go.
Open the Project in Visual Studio
Open up RoundTheCode.Di.sln in Visual Studio.
https://localhost:4000.
https://localhost:4000/di. This will output the Time's property from the singleton, scoped and transient service that we set up.
More Information
You can read more information by viewing our "How to Implement Dependency Injection in ASP.NET Core" article.
Give us your anonymous feedback regarding this page, or any other areas of the website.
Watch .NET tutorials
Subscribe to our YouTube channel
Related code examples
Dependency injection code example for ASP.NET Core
Download an ASP.NET Core dependency injection that allows you to register and test how the singleton, scoped and transient service lifetimes work.