IInstanceScopedAspect Interface
Runtime semantics of aspects that have the same lifetime as instance of types to which their are applied (or instance of the declaring type of members to which they are applied).

Namespace: PostSharp.Aspects
Assembly: PostSharp (in PostSharp.dll) Version: (
public interface IInstanceScopedAspect : IAspect

The IInstanceScopedAspect type exposes the following members.

Public methodCreateInstance
Creates a new instance of the aspect based on the current instance, serving as a prototype.
Public methodRuntimeInitializeInstance
Initializes the aspect instance. This method is invoked when all system elements of the aspect (like member imports) have completed.

When an aspect is instance-scoped, a new instance of this aspect is created whenever an instance of the type to which it has been applied is created (concretely, before the call to the base constructor and the own constructor of this type).

New aspect instances are obtained using the prototype design pattern. As any other aspect, an instance-scope aspect has a static instance initialized at build time, then serialized, deserialized at runtime, and initialized by RuntimeInitialize. This static instance then serves as a prototype. When a new instance of the target type is created, the prototype is cloned by the method CreateInstance(AdviceArgs) (typically implemented by a call to MemberwiseClone()). Then some system initializations (for instance member import) are performed on the aspect instance, and finally the RuntimeInitializeInstance() method is invoked.

When an aspect implementing the IInstanceScopedAspect interface is applied on a static method, field, property, or event, the aspect will be statically scoped and the interface will be ignored.

See Also