MalwareMultiScan/MalwareMultiScan.Backends/Extensions/ServiceCollectionExtensions.cs

72 lines
2.9 KiB
C#
Raw Normal View History

using System;
2020-10-29 16:09:56 +02:00
using System.Diagnostics.CodeAnalysis;
using EasyNetQ;
using MalwareMultiScan.Backends.Backends.Implementations;
2020-10-26 17:06:29 +02:00
using MalwareMultiScan.Backends.Enums;
using MalwareMultiScan.Backends.Interfaces;
2020-10-29 16:09:56 +02:00
using MalwareMultiScan.Backends.Services.Implementations;
using MalwareMultiScan.Backends.Services.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2020-10-26 17:06:29 +02:00
namespace MalwareMultiScan.Backends.Extensions
{
2020-10-29 16:09:56 +02:00
/// <summary>
/// Extensions for IServiceCollection.
/// </summary>
[ExcludeFromCodeCoverage]
public static class ServiceCollectionExtensions
{
2020-10-29 16:09:56 +02:00
/// <summary>
/// Add RabbitMQ service.
/// </summary>
/// <param name="services">Service collection.</param>
/// <param name="configuration">Configuration.</param>
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
{
2020-10-29 16:09:56 +02:00
services.AddSingleton(x =>
RabbitHutch.CreateBus(configuration.GetConnectionString("RabbitMQ")));
}
2020-10-26 17:06:29 +02:00
2020-10-29 16:09:56 +02:00
/// <summary>
/// Add scanning backend.
/// </summary>
/// <param name="services">Service collection.</param>
/// <param name="configuration">Configuration.</param>
/// <exception cref="ArgumentOutOfRangeException">Unknown backend.</exception>
public static void AddScanningBackend(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<IProcessRunner, ProcessRunner>();
2020-10-26 17:06:29 +02:00
2020-10-29 16:09:56 +02:00
switch (configuration.GetValue<BackendType>("BackendType"))
{
2020-10-29 16:09:56 +02:00
case BackendType.Dummy:
services.AddSingleton<IScanBackend, DummyScanBackend>();
break;
case BackendType.Defender:
services.AddSingleton<IScanBackend, WindowsDefenderScanBackend>();
break;
case BackendType.Clamav:
services.AddSingleton<IScanBackend, ClamavScanBackend>();
break;
case BackendType.DrWeb:
services.AddSingleton<IScanBackend, DrWebScanBackend>();
break;
case BackendType.Kes:
services.AddSingleton<IScanBackend, KesScanBackend>();
break;
case BackendType.Comodo:
services.AddSingleton<IScanBackend, ComodoScanBackend>();
break;
case BackendType.Sophos:
services.AddSingleton<IScanBackend, SophosScanBackend>();
break;
case BackendType.McAfee:
services.AddSingleton<IScanBackend, McAfeeScanBackend>();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}