Unity (vi): Using scene Ⅲ: for Dependency Injection (top)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.