[Silverlight getting started series] Prism's MEF dependency injection Singleton Service

Source: Internet
Author: User

MEF's default export and import share attributes are in singleton mode (that is, at most one instance under a iner INER). If it is set[Partcreationpolicy (creationpolicy.Nonshared)]Then, each caller creates an instance. For details, see:

    • Shared: The part author is telling MEF that at most one instance of the part may exist per container.
    • Nonshared: The part author is telling MEF that each request for exports of the part will be served by a new instance of it.
    • Any or not supplied value: The part Author allows the part to be used as either "shared" or "nonshared ".

CodeExample: service export

[Export (Typeof(Imarketfeedservice)]
[Partcreationpolicy (creationpolicy. Shared)]
Public ClassMarketfeedservice: imarketfeedservice, idisposable
{
//....
}

Service reference: Import

[Import]
PublicImarketfeedservice themarketfeedservice {Private Get;Set;}
//Public is required by MEF

In addition, MEF can be composite, that is to say, an export object can also be imported into another object, which is a composite relationship. Therefore, the situation is complex. For details, refer to this article on MEF sharing policy. For more instructions on MEF usage, see this article.

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.