Популярное

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

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

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

Топ запросов

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

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

Автор: Leo Ujjwal

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

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

Описание:

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.

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

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

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

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

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

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

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

Dependency Injection in C# Hindi (हिंदी) | High Coupling vs Low Coupling | Autofac container

Dependency Injection in C# Hindi (हिंदी) | High Coupling vs Low Coupling | Autofac container

Как НА САМОМ ДЕЛЕ научиться хакингу в 2026 году (ОЧЕНЬ КОНКРЕТНО)

Как НА САМОМ ДЕЛЕ научиться хакингу в 2026 году (ОЧЕНЬ КОНКРЕТНО)

Bitwise Operators in Python | Easy and Hindi Explanation | Python Bitwise Operators

Bitwise Operators in Python | Easy and Hindi Explanation | Python Bitwise Operators

Сисадмины больше не нужны? Gemini настраивает Linux сервер и устанавливает cтек N8N. ЭТО ЗАКОННО?

Сисадмины больше не нужны? Gemini настраивает Linux сервер и устанавливает cтек N8N. ЭТО ЗАКОННО?

Stop Writing Messy Code! | Dependency Injection in .NET Core Explained

Stop Writing Messy Code! | Dependency Injection in .NET Core Explained

Почему Собаки Вдруг ЗАЛЕЗАЮТ На Вас? (Причина шокирует)

Почему Собаки Вдруг ЗАЛЕЗАЮТ На Вас? (Причина шокирует)

ДАМПЫ В JAVA на практике, разбираем проблемы

ДАМПЫ В JAVA на практике, разбираем проблемы

Программирование на ассемблере без операционной системы

Программирование на ассемблере без операционной системы

Понимание Active Directory и групповой политики

Понимание Active Directory и групповой политики

Что такое Rest API (http)? Soap? GraphQL? Websockets? RPC (gRPC, tRPC). Клиент - сервер. Вся теория

Что такое Rest API (http)? Soap? GraphQL? Websockets? RPC (gRPC, tRPC). Клиент - сервер. Вся теория

Синтезировал СЛАДКУЮ вату из ОБЫЧНОЙ ваты 🧪

Синтезировал СЛАДКУЮ вату из ОБЫЧНОЙ ваты 🧪

Обзор типичного ФИШИНГОВОГО сайта

Обзор типичного ФИШИНГОВОГО сайта

Python Tutorial for Absolute Beginners #1 - What Are Variables?

Python Tutorial for Absolute Beginners #1 - What Are Variables?

Превратите ЛЮБОЙ файл в знания LLM за СЕКУНДЫ

Превратите ЛЮБОЙ файл в знания LLM за СЕКУНДЫ

Маска подсети — пояснения

Маска подсети — пояснения

Анатомия масштабируемого проекта Python (FastAPI)

Анатомия масштабируемого проекта Python (FastAPI)

Экспресс-курс RAG для начинающих

Экспресс-курс RAG для начинающих

ООП На Простых Примерах | Объектно-Ориентированное Программирование

ООП На Простых Примерах | Объектно-Ориентированное Программирование

Структура файлов и каталогов в Linux

Структура файлов и каталогов в Linux

Как сжимаются изображения? [46 МБ ↘↘ 4,07 МБ] JPEG в деталях

Как сжимаются изображения? [46 МБ ↘↘ 4,07 МБ] JPEG в деталях

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



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



Контакты для правообладателей: infodtube@gmail.com