Skip to content

Commit

Permalink
feature(device-client): Make the DeviceClient and ModuleClient extens…
Browse files Browse the repository at this point in the history
…ible (#1802)
  • Loading branch information
vinagesh committed Mar 22, 2021
1 parent 30225d5 commit a6d21e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 20 additions & 2 deletions iothub/device/src/DeviceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Azure.Devices.Client
/// Contains methods that a device can use to send messages to and receive from the service.
/// </summary>
/// <threadsafety static="true" instance="true" />
public sealed class DeviceClient : IDisposable
public class DeviceClient : IDisposable
{
/// <summary>
/// Default operation timeout.
Expand Down Expand Up @@ -608,7 +608,25 @@ public void SetRetryPolicy(IRetryPolicy retryPolicy)
/// <summary>
/// Releases the unmanaged resources used by the DeviceClient and optionally disposes of the managed resources.
/// </summary>
public void Dispose() => InternalClient?.Dispose();
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by the DeviceClient and allows for any derived class to override and
/// provide custom implementation.
/// </summary>
/// <param name="disposing">Setting to true will release both managed and unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
InternalClient?.Dispose();
InternalClient = null;
}
}

/// <summary>
/// Set a callback that will be called whenever the client receives a state update
Expand Down
22 changes: 20 additions & 2 deletions iothub/device/src/ModuleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.Azure.Devices.Client
/// <summary>
/// Contains methods that a module can use to send messages to and receive from the service and interact with module twins.
/// </summary>
public sealed class ModuleClient : IDisposable
public class ModuleClient : IDisposable
{
private const string ModuleMethodUriFormat = "/twins/{0}/modules/{1}/methods?" + ClientApiVersionHelper.ApiVersionQueryStringLatest;
private const string DeviceMethodUriFormat = "/twins/{0}/methods?" + ClientApiVersionHelper.ApiVersionQueryStringLatest;
Expand Down Expand Up @@ -433,7 +433,25 @@ public void SetRetryPolicy(IRetryPolicy retryPolicy)
/// <summary>
/// Releases the unmanaged resources used by the ModuleClient and optionally disposes of the managed resources.
/// </summary>
public void Dispose() => InternalClient?.Dispose();
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by the ModuleClient and allows for any derived class to override and
/// provide custom implementation.
/// </summary>
/// <param name="disposing">Setting to true will release both managed and unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
InternalClient?.Dispose();
InternalClient = null;
}
}

/// <summary>
/// Set a callback that will be called whenever the client receives a state update
Expand Down

0 comments on commit a6d21e6

Please sign in to comment.