ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

What is Dependency Injection ? With detailed explanation with real time example in simple way.

Автор: Leo Ujjwal

Загружено: 2025-11-02

Просмотров: 22

Описание: What is Dependency Injection ? With detailed explanation with real time example in simple way.

In this video, I'll explain why dependency injection with detailed explanation with real time examples in simple way. Creating loosely coupled code is key to making the code more flexible and more maintainable.

Alright, so let’s start with the most basic and important question —
👉 What exactly is Dependency Injection?

Before we jump into that, let’s first understand the word “Dependency.”

In simple terms, a dependency means something that a class needs in order to do its work.
For example — imagine we have a class called CustomerService, and this class needs to talk to the database to fetch customer data.
To do that, it uses another class called CustomerRepository.

So here, the CustomerService class depends on the CustomerRepository class — and that’s what we call a dependency.

Now, let’s see what happens if we create the CustomerRepository object directly inside the CustomerService class using the new keyword.

public class CustomerService
{
private CustomerRepository _repository = new CustomerRepository();

public void GetCustomer()
{
_repository.GetCustomer();
}
}


At first glance, this looks fine, right?
But the problem here is — our CustomerService class is now tightly coupled with CustomerRepository.

That means:

If tomorrow we want to use a different repository (say SqlRepository or ApiRepository),
we’ll have to modify the CustomerService class.

It also makes unit testing difficult, because we can’t easily replace this dependency with a mock object.

So how do we fix this problem?

That’s where Dependency Injection (DI) comes in.

Dependency Injection is basically a design pattern that helps us remove hard-coded dependencies between classes and make our application loosely coupled and flexible.

In simple words —
👉 Instead of a class creating its own dependencies,
we inject those dependencies from the outside — usually using a constructor, property, or method.

Now, let me make it even simpler.

Think of Dependency Injection like this —
When you go to a restaurant, you don’t bring your own ingredients and cook your food.
You just order it, and the restaurant provides what you need.

Similarly, in Dependency Injection —
your class doesn’t create its own dependencies;
they’re provided or injected from the outside — usually by the .NET Core runtime.

So, Dependency Injection:

Promotes loose coupling

Improves testability

Makes your code cleaner and more maintainable

And the best part is — in .NET Core, Dependency Injection is built-in by default,
which means you don’t need to install or configure any external library for it.

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
 What is Dependency Injection ?  With detailed explanation with real time example in simple way.

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]