संपादित करें

इसके माध्यम से साझा किया गया


CreationPolicy Enum

Definition

Specifies when and how a part will be instantiated.

public enum class CreationPolicy
public enum CreationPolicy
type CreationPolicy = 
Public Enum CreationPolicy
Inheritance
CreationPolicy

Fields

Name Value Description
Any 0

Specifies 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.

Shared 1

Specifies that a single shared instance of the associated ComposablePart will be created by the CompositionContainer and shared by all requestors.

NonShared 2

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.

Applies to