Skip to content

Commit

Permalink
#3491 Remove IDisposable
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Oct 9, 2023
1 parent 1983084 commit 2c47c21
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions Source/Csla.Channels.RabbitMq/RabbitMqProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Csla.Channels.RabbitMq
/// Implements a data portal proxy to relay data portal
/// calls to a remote application server by using RabbitMQ.
/// </summary>
public class RabbitMqProxy : DataPortalProxy, IDisposable
public class RabbitMqProxy : DataPortalProxy
{
/// <summary>
/// Creates an instance of the object, initializing
Expand Down Expand Up @@ -96,6 +96,16 @@ protected virtual void InitializeRabbitMQ()
}
}

private void DisposeRabbitMq()
{
QueueListener?.Dispose();
Connection?.Close();
Channel?.Dispose();
Connection?.Dispose();
Channel = null;
Connection = null;
}

/// <summary>
/// Called by <see cref="DataPortal" /> to create a
/// new business object.
Expand All @@ -109,8 +119,15 @@ public override async Task<DataPortalResult> Create(Type objectType, object crit
if (isSync)
throw new NotSupportedException("isSync == true");

InitializeRabbitMQ();
return await base.Create(objectType, criteria, context, isSync);
try
{
InitializeRabbitMQ();
return await base.Create(objectType, criteria, context, isSync);
}
finally
{
DisposeRabbitMq();
}
}

/// <summary>
Expand All @@ -128,8 +145,15 @@ public override async Task<DataPortalResult> Fetch(Type objectType, object crite
if (isSync)
throw new NotSupportedException("isSync == true");

InitializeRabbitMQ();
return await base.Fetch(objectType, criteria, context, isSync);
try
{
InitializeRabbitMQ();
return await base.Fetch(objectType, criteria, context, isSync);
}
finally
{
DisposeRabbitMq();
}
}

/// <summary>
Expand All @@ -146,8 +170,15 @@ public override async Task<DataPortalResult> Update(object obj, DataPortalContex
if (isSync)
throw new NotSupportedException("isSync == true");

InitializeRabbitMQ();
return await base.Update(obj, context, isSync);
try
{
InitializeRabbitMQ();
return await base.Update(obj, context, isSync);
}
finally
{
DisposeRabbitMq();
}
}

/// <summary>
Expand All @@ -165,8 +196,15 @@ public override async Task<DataPortalResult> Delete(Type objectType, object crit
if (isSync)
throw new NotSupportedException("isSync == true");

InitializeRabbitMQ();
return await base.Delete(objectType, criteria, context, isSync);
try
{
InitializeRabbitMQ();
return await base.Delete(objectType, criteria, context, isSync);
}
finally
{
DisposeRabbitMq();
}
}

/// <summary>
Expand Down Expand Up @@ -206,18 +244,5 @@ private void SendMessage(string sender, string correlationId, string operation,
basicProperties: props,
body: request);
}

/// <summary>
/// Dispose this object and its resources.
/// </summary>
public void Dispose()
{
QueueListener?.Dispose();
Connection?.Close();
Channel?.Dispose();
Connection?.Dispose();
Channel = null;
Connection = null;
}
}
}

0 comments on commit 2c47c21

Please sign in to comment.