LifetimeContext 类

定义

表示生存期树中的节点。Represents a node in the lifetime tree.

public ref class LifetimeContext sealed : System::Composition::CompositionContext, IDisposable
public sealed class LifetimeContext : System.Composition.CompositionContext, IDisposable
type LifetimeContext = class
    inherit CompositionContext
    interface IDisposable
Public NotInheritable Class LifetimeContext
Inherits CompositionContext
Implements IDisposable
继承
LifetimeContext
实现

注解

LifetimeContext对象是共享部件的共享单位。The LifetimeContext object is the unit of sharing for shared parts. 它控制绑定部件的处理方式,并且可用于检索实例(作为现有组合操作的一部分或作为新组合操作的基础)。It controls the disposal of bound parts and can be used to retrieve instances, either as part of an existing composition operation or as the basis of a new composition operation. 可以将单个生存期上下文标记为包含受特定共享边界约束的部分。An individual lifetime context can be marked to contain parts that are constrained by particular sharing boundaries.

此对象包含两个独立受保护的共享状态的部分:共享部件实例和绑定部件实例。This object contains two pieces of independently protected shared state: shared part instances and bound part instances. 共享部件实例是无锁、可读的,如果在处理过程中将其添加到,则不会导致问题。A shared part instance is lock-free, readable, and does not result in issues if it is added to during disposal. 它受锁定。It is protected by being locked itself. 在此锁定下,多样性必然调用了激活逻辑。Activation logic is unavoidably called under this lock. 绑定部件实例始终受锁定保护,不 应在处理后将其写入。A bound part instance is always protected by locking , and should never be written to after disposal. 绑定部件实例在 方法中的锁定下设置为 Dispose()A bound part instance is set to under a lock in the Dispose() method. 如果在对绑定部件实例进行处理后允许写入,则会导致未释放的部分。If writing were allowed after disposal for a bound part instance, it would result in disposable parts not being released. 绑定部件上的 dispose 方法在锁的外部调用。The dispose method on a bound part is called outside of the lock.

方法

AddBoundInstance(IDisposable)

将可释放部件的生存期绑定到此生存期上下文中。Binds the lifetime of a disposable part to this lifetime context.

AllocateSharingId()

生成可用于查找共享部件实例的标识符。Generates an identifier that can be used to locate shared part instances.

Dispose()

释放生存期上下文和所有与之绑定的部件实例。Releases the lifetime context and any part instances bound to it.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindContextWithin(String)

在所有指定的共享边界内查找范围最广的生存期上下文。Finds the broadest lifetime context within all of the specified sharing boundaries.

GetExport(CompositionContract)

检索与指定协定匹配的导出。Retrieves the export that matches the specified contract.

(继承自 CompositionContext)
GetExport(Type)

检索与指定类型匹配的导出。Retrieves the export that matches the specified type.

(继承自 CompositionContext)
GetExport(Type, String)

检索与指定名称和类型匹配的导出。Retrieves the export that matches the specified name and type.

(继承自 CompositionContext)
GetExport<TExport>()

检索与指定泛型类型参数匹配的导出。Retrieves the export that matches the specified generic type parameter.

(继承自 CompositionContext)
GetExport<TExport>(String)

检索与指定泛型类型参数和协定名称匹配的导出。Retrieves the export that matches the specified generic type parameter and contract name.

(继承自 CompositionContext)
GetExports(Type)

检索与指定类型匹配的所有导出的集合。Retrieves a collection of all exports that match the specified type.

(继承自 CompositionContext)
GetExports(Type, String)

检索所有与指定协定名称和类型匹配的导出。Retrieves all exports that match the specified contract name and type.

(继承自 CompositionContext)
GetExports<TExport>()

检索与指定泛型类型参数匹配的所有导出。Retrieves all exports that match the specified generic type parameter.

(继承自 CompositionContext)
GetExports<TExport>(String)

检索所有与指定泛型类型参数和协定名称匹配的导出。Retrieves all exports that match the specified generic type parameter and contract name.

(继承自 CompositionContext)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetOrCreate(Int32, CompositionOperation, CompositeActivator)

检索具有指定 ID 的共享部件实例,或如果找不到该部件实例,则在指定操作中使用指定创建器创建并共享一个部件实例。Retrieves a shared part instance with the specified ID, or if the part instance can not be found, creates and shares a part instance using the specified creator within the specified operation.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回此 LifetimeContext 对象的字符串表示形式。Returns the string representation of this LifetimeContext object.

TryGetExport(CompositionContract, Object)

从组合上下文中检索协定实例。Retrieves a contract instance from the composition context.

TryGetExport(Type, Object)

如果未找到匹配项,则返回与指定的类型匹配的导出,或返回 nullReturns the export that matches the specified type, or returns null if no match is found.

(继承自 CompositionContext)
TryGetExport(Type, String, Object)

如果未找到匹配项,则返回与指定的协定名称和类型匹配的导出,或返回 nullReturns the export that matches the specified contract name and type, or returns null if no match is found.

(继承自 CompositionContext)
TryGetExport<TExport>(String, TExport)

如果未找到匹配项,则返回与指定的泛型类型参数和协定名称匹配的导出,或返回 nullReturns the export that matches the specified generic type parameter and contract name, or returns null if no match is found.

(继承自 CompositionContext)
TryGetExport<TExport>(TExport)

如果未找到匹配项,则返回与指定的泛型类型参数匹配的导出,或返回 nullReturns the export that matches the specified generic type parameter, or returns null if no match is found.

(继承自 CompositionContext)

扩展方法

SatisfyImports(CompositionContext, Object)

满足从指定上下文中的指定物体的导入。Satisfies the imports of the specified object from the specified context.

SatisfyImports(CompositionContext, Object, AttributedModelProvider)

使用指定的约定,满足从指定上下文中的指定物体的导入。Satisfies the imports of the specified object from the specified context, using the specified conventions.

适用于