🚧 Add modules to DI, rename classes

This commit is contained in:
2020-03-02 08:49:57 +04:00
parent 1299e4dc7e
commit dc2307d74e
5 changed files with 60 additions and 55 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ namespace Kruzya.TelegramBot.Core
if (module == null) if (module == null)
{ {
module = (Module) Activator.CreateInstance(moduleType, this); module = (Module) Activator.CreateInstance(moduleType, this);
Console.WriteLine($"Started module {module.GetType().FullName}"); Console.WriteLine($"Started module {module.GetType().Name}");
_modules.Add(module); _modules.Add(module);
} }
+5
View File
@@ -25,6 +25,11 @@ namespace Kruzya.TelegramBot.Core
services.AddTelegramBot(); services.AddTelegramBot();
services.AddLogging(builder => builder.AddConsole()); 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); _core.Modules.ConfigureServices(services);
} }
@@ -4,9 +4,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Kruzya.TelegramBot.CombotAntiSpam namespace Kruzya.TelegramBot.CombotAntiSpam
{ {
public class Startup : Module public class CombotAntiSpam : Module
{ {
public Startup(Core.Core core) : base(core) public CombotAntiSpam(Core.Core core) : base(core)
{ {
} }
@@ -11,9 +11,9 @@ using Telegram.Bot.Types;
namespace Kruzya.TelegramBot.RichSiteSummary namespace Kruzya.TelegramBot.RichSiteSummary
{ {
public class Startup : Module public class RichSiteSummary : Module
{ {
public Startup(Core.Core core) : base(core) public RichSiteSummary(Core.Core core) : base(core)
{ {
} }
@@ -7,7 +7,7 @@ using Telegram.Bot.Types;
namespace Kruzya.TelegramBot.RichSiteSummary namespace Kruzya.TelegramBot.RichSiteSummary
{ {
public static class RichSiteSummaryRepositoryExtension internal static class RichSiteSummaryRepositoryExtension
{ {
#region Subscriber #region Subscriber