CreationPolicy Enumeration

Specifies when and how a part will be instantiated.

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

'Declaration
Public Enumeration CreationPolicy

Member nameDescription
AnySpecifies 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.
SharedSpecifies that a single shared instance of the associated ComposablePart will be created by the CompositionContainer and shared by all requestors.
NonSharedSpecifies that a new non-shared instance of the associated ComposablePart will be created by the CompositionContainer for every requestor.

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.

Silverlight

Supported in: 5, 4

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

Community Additions

ADD
Show: