Able to explain what dependency injection is and what problem it solves Flashcards

1
Q

dependency

A

A software dependency is

  • a relationship between software components
  • where one component relies on the other to work properly.
  • For example, if a software application uses a framework to query a database, the application depends on that framework .
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Able to explain what dependency injection

A

Dependency injection is

  • a design pattern used in web development
  • to make code more flexible and manageable.
  • It helps solve the problem of managing dependencies between different parts of a web application.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

dependency injection what problem it solves

A

example:

  • Imagine you’re building a website,
  • and different parts of the code need access to a database.
  • Without dependency injection,
    • each component would directly create its own database connection
    • or access the database directly.
  • It makes the code difficult to test and change.

Dependency injection solves this problem

  • by introducing a separate object,
    • often called a “container” or “injector,” to manage the dependencies.
  • Instead of each component creating its own dependencies,
    • the injector takes care of creating and providing the necessary dependencies
    • to the components that need them.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dependency injection in the project

A

The constructor takes three parameters of types

  • IUserDbServices,
  • IConfiguration,
  • IEmailServices,

and assigns them to the respective private fields _dbcontext, _configuration, and _emailServices.

  • These interfaces are then used throughout the UsersDbController class to interact with the corresponding services..
How well did you know this?
1
Not at all
2
3
4
5
Perfectly