diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-07-13 08:15:07 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-07-13 08:15:07 -0700 |
commit | ed58e313d363a6500fabd5873c3563dffeff7c2d (patch) | |
tree | 2b52401302285cdfa821446888f34810dee0a916 | |
parent | 1fced6e40e8fa930e8876b93020d9e05163f92f9 (diff) | |
download | DotNetOpenAuth-ed58e313d363a6500fabd5873c3563dffeff7c2d.zip DotNetOpenAuth-ed58e313d363a6500fabd5873c3563dffeff7c2d.tar.gz DotNetOpenAuth-ed58e313d363a6500fabd5873c3563dffeff7c2d.tar.bz2 |
Fixed OpenIdRelyingPartyControlBase to Dispose of any OpenIdRelyingParty instances it creates.
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyControlBase.cs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyControlBase.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyControlBase.cs index 7d8d49a..a744120 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyControlBase.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyControlBase.cs @@ -30,7 +30,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// A common base class for OpenID Relying Party controls. /// </summary> [DefaultProperty("Identifier"), ValidationProperty("Identifier")] - public abstract class OpenIdRelyingPartyControlBase : Control { + public abstract class OpenIdRelyingPartyControlBase : Control, IDisposable { /// <summary> /// The manifest resource name of the javascript file to include on the hosting page. /// </summary> @@ -184,6 +184,12 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { private OpenIdRelyingParty relyingParty; /// <summary> + /// A value indicating whether the <see cref="relyingParty"/> field contains + /// an instance that we own and should Dispose. + /// </summary> + private bool relyingPartyOwned; + + /// <summary> /// Initializes a new instance of the <see cref="OpenIdRelyingPartyControlBase"/> class. /// </summary> protected OpenIdRelyingPartyControlBase() { @@ -278,12 +284,18 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { get { if (this.relyingParty == null) { this.relyingParty = this.CreateRelyingParty(); + this.relyingPartyOwned = true; } return this.relyingParty; } set { + if (this.relyingPartyOwned && this.relyingParty != null) { + this.relyingParty.Dispose(); + } + this.relyingParty = value; + this.relyingPartyOwned = false; } } @@ -444,6 +456,29 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// <summary> + /// Enables a server control to perform final clean up before it is released from memory. + /// </summary> + [SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Base class doesn't implement virtual Dispose(bool), so we must call its Dispose() method.")] + public sealed override void Dispose() { + this.Dispose(true); + base.Dispose(); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + protected virtual void Dispose(bool disposing) { + if (disposing) { + if (this.relyingPartyOwned && this.relyingParty != null) { + this.relyingParty.Dispose(); + this.relyingParty = null; + } + } + } + + /// <summary> /// Creates the authentication requests for a given user-supplied Identifier. /// </summary> /// <returns>A sequence of authentication requests, any one of which may be |