20 lines
745 B
C#
20 lines
745 B
C#
using BMA.EHR.Leave.Service.Services;
|
|
using Microsoft.Extensions.ObjectPool;
|
|
using RabbitMQ.Client;
|
|
|
|
namespace BMA.EHR.Leave.Service.Extensions
|
|
{
|
|
public static class RabbitMqServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddRabbitMqConnectionPooling(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
|
|
services.AddSingleton<ObjectPool<IModel>>(sp =>
|
|
{
|
|
var provider = sp.GetRequiredService<ObjectPoolProvider>();
|
|
return provider.Create(new RabbitMqConnectionPoolPolicy(configuration));
|
|
});
|
|
return services;
|
|
}
|
|
}
|
|
}
|