mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
🚧 Add modules to DI, rename classes
This commit is contained in:
+1
-1
@@ -151,7 +151,7 @@ namespace Kruzya.TelegramBot.Core
|
||||
if (module == null)
|
||||
{
|
||||
module = (Module) Activator.CreateInstance(moduleType, this);
|
||||
Console.WriteLine($"Started module {module.GetType().FullName}");
|
||||
Console.WriteLine($"Started module {module.GetType().Name}");
|
||||
_modules.Add(module);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,12 @@ namespace Kruzya.TelegramBot.Core
|
||||
{
|
||||
services.AddTelegramBot();
|
||||
services.AddLogging(builder => builder.AddConsole());
|
||||
|
||||
// Add all modules to DI with Core instance.
|
||||
services.AddSingleton<Core>(_core);
|
||||
foreach (var module in _core.Modules) services.AddSingleton(module.GetType(), module);
|
||||
|
||||
// Trigger module handlers.
|
||||
_core.Modules.ConfigureServices(services);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam
|
||||
{
|
||||
public class Startup : Module
|
||||
{
|
||||
public Startup(Core.Core core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<ICombotClient, CombotClient>();
|
||||
}
|
||||
}
|
||||
}
|
||||
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam
|
||||
{
|
||||
public class CombotAntiSpam : Module
|
||||
{
|
||||
public CombotAntiSpam(Core.Core core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<ICombotClient, CombotClient>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,36 @@
|
||||
using System;
|
||||
using BotFramework;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||
using Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
||||
{
|
||||
public class Startup : Module
|
||||
{
|
||||
public Startup(Core.Core core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<RichSiteSummaryContext>(options =>
|
||||
options.UseLazyLoadingProxies()
|
||||
.UseMySql(Configuration.GetConnectionString("RichSiteSummary")));
|
||||
|
||||
services.AddTelegramBotParameterParser<Feed, DbResolverParameter<Feed, RichSiteSummaryContext>>()
|
||||
.AddTelegramBotParameterParser<Post, DbResolverParameter<Post, RichSiteSummaryContext>>()
|
||||
.AddTelegramBotParameterParser<Subscriber, DbResolverParameter<Subscriber, RichSiteSummaryContext>>();
|
||||
|
||||
services.AddQueue<UserMessage>()
|
||||
.AddQueue<UserUnsubscribe>();
|
||||
|
||||
services.AddHostedService<RssFetch>();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using BotFramework;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||
using Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
||||
{
|
||||
public class RichSiteSummary : Module
|
||||
{
|
||||
public RichSiteSummary(Core.Core core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<RichSiteSummaryContext>(options =>
|
||||
options.UseLazyLoadingProxies()
|
||||
.UseMySql(Configuration.GetConnectionString("RichSiteSummary")));
|
||||
|
||||
services.AddTelegramBotParameterParser<Feed, DbResolverParameter<Feed, RichSiteSummaryContext>>()
|
||||
.AddTelegramBotParameterParser<Post, DbResolverParameter<Post, RichSiteSummaryContext>>()
|
||||
.AddTelegramBotParameterParser<Subscriber, DbResolverParameter<Subscriber, RichSiteSummaryContext>>();
|
||||
|
||||
services.AddQueue<UserMessage>()
|
||||
.AddQueue<UserUnsubscribe>();
|
||||
|
||||
services.AddHostedService<RssFetch>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
||||
{
|
||||
public static class RichSiteSummaryRepositoryExtension
|
||||
internal static class RichSiteSummaryRepositoryExtension
|
||||
{
|
||||
#region Subscriber
|
||||
|
||||
|
||||
Reference in New Issue
Block a user