Dependency Injection - Explanation

Recently, I was asked to express CI in conversation.

I replied:

1) I go to the hotel. I ordered food. The hotel asks me to clean the dishes and clean the tables. So, I am a client, I am responsible for managing the service (create, execute, delete). But DI separates these tasks, so the service consumer does not need to worry about monitoring the life cycle of the service.

2) He also asked if there is any microsoft API after DI? .I answered (that was my guess). In WCF, you can create proxies using ChannelFactory, which controls the lifetime of your factory.

for paragraph (1) he said that only 10% is correct

for item (2), he said it was a factory pattern that was independent of injection.

Actually, what went wrong in my explanations (except for my bad English)? What are the real answers for them?

I look forward to your valuable suggestions.

+3
source share
3 answers

1.

I think that in your example of a hotel it is more like what you seem to eat, and you will be asked to first build a kitchen, fashion plates, bowls and utensils, build a table and chair, grow wheat and vegetables, kill and butcher meat, and then cook and peel.

- /. - . . , . , , - , , , , .

, , , "" . .

2.

, Microsoft Patterns and Practices/Enterprise Library DI Unity ( ), , ASP.NET MVC DI.

+3

, , , , . .

, DI , BCL.

, System.IO.StreamWriter - . :

public StreamWriter(Stream stream);

Stream , , StreamWriter.

WCF - Factory. , DI, DI .

+2

, "", , , . :

  • Injection Dependency . .

  • framework, , , , . , Linq .

0

Source: https://habr.com/ru/post/1740287/


All Articles