Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

CreationPolicy Enumeration

Specifies when and how a part will be instantiated.

Namespace:  System.ComponentModel.Composition
Assembly:  System.ComponentModel.Composition (in System.ComponentModel.Composition.dll)
public enum CreationPolicy
Member nameDescription
Supported by Portable Class LibraryAnySpecifies that the CompositionContainer will use the most appropriate CreationPolicy for the part given the current context. This is the default CreationPolicy. By default, CompositionContainer will use Shared, unless the ComposablePart or importer requests NonShared.
Supported by Portable Class LibraryNonSharedSpecifies that a new non-shared instance of the associated ComposablePart will be created by the CompositionContainer for every requestor.
Supported by Portable Class LibrarySharedSpecifies that a single shared instance of the associated ComposablePart will be created by the CompositionContainer and shared by all requestors.

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.

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.