2022-02-16 17:43:57 +02:00
|
|
|
using System.Reflection;
|
|
|
|
|
using Kruzya.TelegramBot.Core;
|
2022-02-16 17:07:30 +02:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using West.TelegramBot.ContentStore.Service;
|
2022-02-16 17:43:57 +02:00
|
|
|
using Module = Kruzya.TelegramBot.Core.Module;
|
2022-02-16 17:07:30 +02:00
|
|
|
|
|
|
|
|
namespace West.TelegramBot.ContentStore;
|
|
|
|
|
|
|
|
|
|
public class ContentStore : Module
|
|
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
public readonly List<Type> MediaServiceTypes = new();
|
2022-02-16 17:43:57 +02:00
|
|
|
|
2022-02-16 17:07:30 +02:00
|
|
|
public ContentStore(Core core) : base(core)
|
|
|
|
|
{
|
2022-02-16 17:43:57 +02:00
|
|
|
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
|
|
|
{
|
|
|
|
|
foreach (var exportedType in assembly.GetExportedTypes()
|
2022-02-16 18:08:02 +02:00
|
|
|
.Where(t => !t.IsAbstract && t.GetInterface(nameof(IRandomMediaService)) != null))
|
2022-02-16 17:43:57 +02:00
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
MediaServiceTypes.Add(exportedType);
|
2022-02-16 17:43:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-16 17:07:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
foreach (var serviceType in MediaServiceTypes)
|
2022-02-16 17:43:57 +02:00
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
services.AddSingleton(typeof(IRandomMediaService), serviceType);
|
2022-02-16 17:43:57 +02:00
|
|
|
}
|
2022-02-16 17:07:30 +02:00
|
|
|
}
|
|
|
|
|
}
|