ASP.NET: Dependency Injection
Learn about the dependency injection programming pattern and how it is used to improve code in ASP.NET applications
StartKey Concepts
Review core concepts you need to learn to master this subject
Dependency
Dependency Injection
IoC Container
Registering Services
AddRazorPages()
AddDbContext
Dependencies As Interfaces
DI and IOC Container
Dependency
Dependency
// Object A - the class that depends on Object B
class Reviewer
{
private EmailSender Sender = new EmailSender();
public SendReview(string lesson, string comments)
{
Sender.SendReview(lesson, comments);
}
}
// Object B - the dependency
class EmailSender
{
public SendReview(string lesson, string comments)
{
// Send an email with the Lesson and Comments
}
}
static void Main(string[] args)
{
Reviewer reviewer = new Reviewer().
SendReview("Dependecy Injection", "Learned a ton!");
}
When one object (Object A) references another object (Object B), using its properties and methods, it means that the first object (A) depends on the second (B), making the second object (B) a dependency.
Dependency Injection
Lesson 1 of 1
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory