MEF Basic Concepts

Source: Internet
Author: User

Export is a component (part) that provides a value (values) to another part through a container (Container). The Export attribute modifies a class, field, property, or method, and the Import attribute can decorate a field, property, or constructor parameter.

For the export and import to match, both parties need to use the same contract, which includes the contract name and contract Type. Both are explicit implicit. Experience the code below

 Public class myclass{    [Import]    publicgetset;}        [Export (typeof(IMyAddin))]      Public class Mylogger:imyaddin {}       // Won't match the previous import!     Public class Mylogger:imyaddin {}    }

Import the Export field. It is important to note that the import and export need to have the same contracttype, if the contractname is consistent, the type is inconsistent and still cannot be used

 Public classmyclass{[Import ("MajorRevision")]     Public intMajorRevision {Get;Set; }} Public classmyexportclass{[Export ("MajorRevision")]//This one would match.     Public intMajorRevision =4; [Export ("minorrevision")]     Public intMinorrevision = -;}

Types of Imports

MEF Basic Concepts

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.