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.