Похожие чаты

If you don't have DI then you will have to

instantiate dependencies manually, usually inside constructor. For example:
public class UserService {
private UserRepository userRepository;

public UserService() {
this.userRepository = new UserRepositoryImpl();
}
}

Well this may look simple, right? But what if your component has three dependencies, and those dependencies also have their own dependencies? So you have to write something like this in your constructor:
this.userRepository = new UserRepositoryImpl(new EntityManager());
this.someOtherDepenpency = new SomeOtherDependency(new ExternalDependencyOne(), new ExternalDependencyTwo(new ExternalDependencyThree()));
// etc
This will quickly become a headache as your application becomes more complex

1 ответов

14 просмотров

so how DI can help me i this case the example in the end

Похожие вопросы

Обсуждают сегодня

коллеги, добрый вечер! А никто не знает как модальная форма может себя закрыть? Ну допустим модальная форма определила, что смысла ей работать нет и хочет вернуть modalResult...
Михаил
83
@everyone Hello Future! We are extremely excited to announce the hottest season ever: DeFi Summer 2024 🔥 Introducing the Stake and Burn Model: You Stake yours, we Burn...
Dennis The Menace
1
средствами IBX как-то можно выполнить запрос insert ... returning?
Igor
30
Had my LGCY in a CEX and transferred it to a pvt wallet in Dec 2021. Haven't touched it since. So, I just have to wait for the team to release the swap contract to swap to LG...
💎 Hands
20
KDSwap, a decentralized exchange (DEX) built on Kadena, is setting a new standard by working towards becoming a MiCA-compliant DEX in Europe. What sets KDSwap apart? While ...
Mal (will not DM you first) Sutton
20
Bagging more KDA. Lots of projects are affected by market conditions. So is this. When the mist clears we will see KDA as one of the leaders. Would I like this now as of...
Kenny
10
объясните, я прада не понимаю. зачем в перле нужен аниивент? кому он пригодился в действительно нагруженных проектах?
nerv
30
Никто случаем не знает, как по-хорошему делается дозапись текста в edit на винапи?
The Bird of Hermes
25
Составить программу для подсчета числа нулевых символов с использованием команд управления циклом loop. Мы проходили TASM, если вдруг нужно будет. Если никто не хочет помогать...
Гарри Поттер
10
hi all, just joined. I would like to learn about real world implementations of the protocol and data NFTs, are there some good examples that I can check out?
Brad | Co-Founder & CEO
13
Карта сайта