Export (0) Print
Expand All

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
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. Be default, CompositionContainer will use Shared, unless the ComposablePart or importer requests NonShared.
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.
Supported by Portable Class LibraryNonSharedSpecifies 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.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft