O'Reilly logo

ASP.NET Core Essentials by Shahed Chowdhuri

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing DI in ASP.NET Core

Before we proceed, you may be surprised to know that we already have DI in the sample project that we have been working with in earlier chapters. Take a look at the Startup.cs file in your web project folder. You should see the following code near the end of the ConfigureServices() method:

services.AddTransient<IEmailSender, AuthMessageSender>(); 
services.AddTransient<ISmsSender, AuthMessageSender>(); 

This code adds a couple of instances of the AuthMessageSender service class, which implements both the IEmailSender and ISmsSender interfaces. The code for this class and its interfaces can be found in the Services subfolder of your project, as shown in the following screenshot:

The call to AddTransient ensures that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required