Skip to content

Dependency Injection

JessicaOPRD edited this page Feb 28, 2023 · 3 revisions

I have many notes and even a presentation about this. Some notes for comparison below:

Benefits

  • Reduces tight coupling
  • Reduces need to establish new objects per use, if singleton behavior makes sense

.NET

  • Often object instances to be passed in the constructor are referred to as "services."
  • Added through the web application builder
// Framework services (built into core or an add-on)
builder.Services.AddControllerWithView();

// Custom services
builder.Services.AddScoped<ILoggerService, LoggerService>();