using System;
using System.Diagnostics.CodeAnalysis;
using EasyNetQ;
using MalwareMultiScan.Backends.Backends.Implementations;
using MalwareMultiScan.Backends.Enums;
using MalwareMultiScan.Backends.Interfaces;
using MalwareMultiScan.Backends.Services.Implementations;
using MalwareMultiScan.Backends.Services.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace MalwareMultiScan.Backends.Extensions
{
///
/// Extensions for IServiceCollection.
///
[ExcludeFromCodeCoverage]
public static class ServiceCollectionExtensions
{
///
/// Add RabbitMQ service.
///
/// Service collection.
/// Configuration.
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton(x =>
RabbitHutch.CreateBus(configuration.GetConnectionString("RabbitMQ")));
}
///
/// Add scanning backend.
///
/// Service collection.
/// Configuration.
/// Unknown backend.
public static void AddScanningBackend(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton();
switch (configuration.GetValue("BackendType"))
{
case BackendType.Dummy:
services.AddSingleton();
break;
case BackendType.Defender:
services.AddSingleton();
break;
case BackendType.Clamav:
services.AddSingleton();
break;
case BackendType.DrWeb:
services.AddSingleton();
break;
case BackendType.Kes:
services.AddSingleton();
break;
case BackendType.Comodo:
services.AddSingleton();
break;
case BackendType.Sophos:
services.AddSingleton();
break;
case BackendType.McAfee:
services.AddSingleton();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}