About Dependency Injection
What is dependency injection, I think this problem I said here is not appropriate, so I recommend the master's article. Previous articles have also mentioned that "Martin Fowler's inversion of control containers and the Dependency injection pattern are to be recommended, of course, if the reading is more laborious, Lu Zhenyu, do you really know about IOC and AOP? Series is also a good reference. "
One more thing to say here is that dependency injection (Dependency injection) and control reversal (inversion) are not the same concept, and some people often mix together. With that in mind, look at Martin's article in front of me.
Preparatory work
For the next instructions, we first write a few of the interfaces and classes that are needed later.
Note: This article refers to the Iorder interface, Commonorder class, Viporder class and ILogger interface, Consolelogger class, Nulllogger Class code see Unity (III): QuickStart and Unity (v) : Use scenario Ⅱ: For preparing code in a single case pattern, this is not repeated here.
Iorderwithlogging Interface:
There are three kinds of dependency injection methods supported by Unity: constructor injection, set value injection, method invocation injection.
Constructor injection
For constructor injection, unity supports two ways of dependency injection: automatic dependency Injection and labeling by marking. Specifically, you can use automatic dependency injection for target classes that have only a single constructor, and for target classes with multiple constructors, you should use a label on the constructor to inject.