refactor,feat: 批量代码重构与新增业务模块
1. 重命名枚举项与实体字段,修正类型引用 2. 新增IsNull扩展方法与多项字符串处理扩展 3. 新增大量业务DTO、服务接口与枚举定义 4. 重构RabbitMQ服务实现,替换旧版消息队列组件 5. 优化签到服务的宠物喂养事务逻辑 6. 移除冗余的项目引用与旧版消息队列代码 7. 新增Excel导出、导入模板相关工具方法
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
using RabbitMQ.Client;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Infrastructure.RabbitMQ
|
||||
{
|
||||
public interface IRabbitMQConnection : IDisposable
|
||||
{
|
||||
Task<IChannel> CreateChannel();
|
||||
}
|
||||
|
||||
public class RabbitMQConnection : IRabbitMQConnection
|
||||
{
|
||||
private readonly ConnectionFactory _factory;
|
||||
private readonly IConnection _connection;
|
||||
private bool _isDisposed;
|
||||
|
||||
public RabbitMQConnection(ConnectionFactory factory)
|
||||
{
|
||||
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
|
||||
_connection = factory.CreateConnectionAsync().Result;
|
||||
}
|
||||
|
||||
public async Task<IChannel> CreateChannel()
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
return await _connection.CreateChannelAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
// Free any other managed objects here.
|
||||
}
|
||||
|
||||
// Free any unmanaged objects here.
|
||||
_connection.Dispose();
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
|
||||
~RabbitMQConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
private void EnsureNotDisposed()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
throw new ObjectDisposedException(nameof(RabbitMQConnection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user