CreationPolicy CreationPolicy CreationPolicy CreationPolicy Enum

定义

指定何时以及如何实例化部件。Specifies when and how a part will be instantiated.

public enum class CreationPolicy
public enum CreationPolicy
type CreationPolicy = 
Public Enum CreationPolicy
继承
CreationPolicyCreationPolicyCreationPolicyCreationPolicy

字段

Any Any Any Any 0

指定 CompositionContainer 将为部件使用给定当前上下文中最适当的 CreationPolicySpecifies that the CompositionContainer will use the most appropriate CreationPolicy for the part given the current context. 这是默认的 CreationPolicyThis is the default CreationPolicy. 默认情况下,除非 CompositionContainer 或导入程序请求 Shared,否则 ComposablePart 将使用 NonSharedBy default, CompositionContainer will use Shared, unless the ComposablePart or importer requests NonShared.

NewScope NewScope NewScope NewScope 3
NonShared NonShared NonShared NonShared 2

指定将由 ComposablePart 为每个请求者创建一个关联的 CompositionContainer 的新的非共享实例。Specifies that a new non-shared instance of the associated ComposablePart will be created by the CompositionContainer for every requestor.

Shared Shared Shared Shared 1

指定将由 ComposablePart 创建关联的 CompositionContainer 的单个共享实例,并由所有请求者共享该实例。Specifies that a single shared instance of the associated ComposablePart will be created by the CompositionContainer and shared by all requestors.

注解

在撰写过程中, CompositionContainer需要通过导出描述的对象的实例来填充导入。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.

发生哪种行为取决于CreationPolicy附加RequiredCreationPolicyImportAttribute导出PartCreationPolicyAttribute的的属性和的。Which behavior occurs depends on the CreationPolicy property of the PartCreationPolicyAttribute attached to the export and the RequiredCreationPolicy of the ImportAttribute. 这两个将包含CreationPolicy枚举中的一个值。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 CreationPolicy Export 指定任何指定的或 none。Export's CreationPolicy specifies Any or none specified. CreationPolicy导出指定共享Export's CreationPolicy specifies Shared CreationPolicy导出指定了非共享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.
SharedShared 将创建导出对象的单个共享实例。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.

适用于