Freigeben über


CreationPolicy Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies when and how a part will be instantiated.

Namespace:  System.ComponentModel.Composition
Assembly:  System.ComponentModel.Composition (in System.ComponentModel.Composition.dll)

Syntax

'Declaration
Public Enumeration CreationPolicy
public enum CreationPolicy

Members

Member name Description
Any Specifies that the CompositionContainer will use the most appropriate CreationPolicy for the part given the current context. This is the default CreationPolicy. Be default, CompositionContainer will use Shared, unless the ComposablePart or importer requests NonShared.
Shared Specifies that a single shared instance of the associated ComposablePart will be created by the CompositionContainer and shared by all requestors.
NonShared Specifies that a new non-shared instance of the associated ComposablePart will be created by the CompositionContainer for every requestor.

Remarks

In the course of composition, the CompositionContainer needs instances of the objects described by exports in order to fill imports. If a one export is used to fill multiple imports, there are two possible behaviors. Either a single instance of the exported object is created, and a reference to the same object is given to every importer, or a separate instance of the exported object is created for each importer.

Which behavior occurs depends on the CreationPolicy property of the PartCreationPolicyAttribute attached to the export and the RequiredCreationPolicy of the ImportAttribute. Both of which will contain a value from the CreationPolicy enumeration. If the policies are incompatible, that export will not be considered a match for the given import. The following table summarizes the interaction of these two properties.

RequiredCreationPolicy

Export's CreationPolicy specifies Any or none specified.

Export's CreationPolicy specifies Shared

Export's CreationPolicy specifies NonShared

Any

A single, shared instance of the exported object will be created.

A single, shared instance of the exported object will be created.

A new instance of the exported object will be created for each importer.

Shared

A single, shared instance of the exported object will be created.

A single, shared instance of the exported object will be created.

The export will not be considered a match for the import.

NonShared

A new instance of the exported object will be created for each importer.

The export will not be considered a match for the import.

A new instance of the exported object will be created for each importer.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.