/// <summary> /// Performs application-defined tasks associated with /// freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (!this.IsDisposed && this.domainContext != null) { DomainParticipantAttribute.ApplyDisposal( this.GetType(), this, this.domainContext); } this.Dispose(true); GC.SuppressFinalize(this); }
/// <summary> /// Applies disposal routines from any domain participant /// attributes specified on a domain type to a domain context. /// </summary> /// <param name="type"> /// A domain type. /// </param> /// <param name="instance"> /// A domain instance, if applicable. /// </param> /// <param name="context"> /// A domain context. /// </param> public static void ApplyDisposal( Type type, object instance, DomainContext context) { Ensure.NotNull(type, "type"); Ensure.NotNull(context, "context"); var attributes = type.GetCustomAttributes( typeof(DomainParticipantAttribute), false); foreach (DomainParticipantAttribute attribute in attributes.Reverse()) { attribute.Dispose(context, type, instance); } if (type.BaseType != null) { DomainParticipantAttribute.ApplyDisposal( type.BaseType, instance, context); } }