This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Saturday, February 3, 2024

what is dependency injection in asp.net core

 what is dependency injection in asp.net core


 Introduction dependency injection in asp.net core:


ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. For more information specific to dependency injection within MVC controllers, see Dependency injection into controllers in ASP.NET Core.


What is dependency injection with example?


What is dependency injection? Classes often require references to other classes. For example, a Car class might need a reference to an Engine class. These required classes are called dependencies, and in this example the Car class is dependent on having an instance of the Engine class to run.


Example dependency injection in asp.net core:


class Bar : IBar { 

  // ...

}


class Foo {

  private readonly IBar _bar;

  public Foo(IBar bar) {

    _bar = bar;

  }

}


No comments:

Post a Comment