From 2c47c21850342c360b0e7b4d75abe3c4d5715f03 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Mon, 9 Oct 2023 19:41:07 +0200 Subject: [PATCH] #3491 Remove IDisposable --- .../Csla.Channels.RabbitMq/RabbitMqProxy.cs | 69 +++++++++++++------ 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/Source/Csla.Channels.RabbitMq/RabbitMqProxy.cs b/Source/Csla.Channels.RabbitMq/RabbitMqProxy.cs index ddd7128fe7..20beb69855 100644 --- a/Source/Csla.Channels.RabbitMq/RabbitMqProxy.cs +++ b/Source/Csla.Channels.RabbitMq/RabbitMqProxy.cs @@ -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. /// - public class RabbitMqProxy : DataPortalProxy, IDisposable + public class RabbitMqProxy : DataPortalProxy { /// /// Creates an instance of the object, initializing @@ -96,6 +96,16 @@ protected virtual void InitializeRabbitMQ() } } + private void DisposeRabbitMq() + { + QueueListener?.Dispose(); + Connection?.Close(); + Channel?.Dispose(); + Connection?.Dispose(); + Channel = null; + Connection = null; + } + /// /// Called by to create a /// new business object. @@ -109,8 +119,15 @@ public override async Task 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(); + } } /// @@ -128,8 +145,15 @@ public override async Task 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(); + } } /// @@ -146,8 +170,15 @@ public override async Task 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(); + } } /// @@ -165,8 +196,15 @@ public override async Task 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(); + } } /// @@ -206,18 +244,5 @@ private void SendMessage(string sender, string correlationId, string operation, basicProperties: props, body: request); } - - /// - /// Dispose this object and its resources. - /// - public void Dispose() - { - QueueListener?.Dispose(); - Connection?.Close(); - Channel?.Dispose(); - Connection?.Dispose(); - Channel = null; - Connection = null; - } } } \ No newline at end of file