mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
basic architecture change: consul + hangfire
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Consul;
|
||||
using Hangfire;
|
||||
using Hangfire.Redis;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace MalwareMultiScan.Shared.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions for IServiceCollection.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Add consul to the service collection and register the node on start.
|
||||
/// </summary>
|
||||
/// <param name="services">Service collection.</param>
|
||||
/// <param name="configuration">Configuration.</param>
|
||||
public static void AddConsul(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddSingleton<IConsulClient>(new ConsulClient(config =>
|
||||
{
|
||||
config.Address = configuration.GetValue<Uri>("CONSUL_ADDRESS");
|
||||
}));
|
||||
}
|
||||
|
||||
public static void AddHangfire(this IServiceCollection services,
|
||||
IConfiguration configuration, params string[] queues)
|
||||
{
|
||||
if (queues.Length == 0)
|
||||
queues = new[] {"default"};
|
||||
|
||||
services.AddHangfire(options =>
|
||||
options.UseRedisStorage(configuration.GetValue<string>("REDIS_ADDRESS")));
|
||||
|
||||
services.AddHangfireServer(options => options.Queues = queues);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user