diff --git a/Core/Core.cs b/Core/Core.cs index d71056c..bfe27e2 100644 --- a/Core/Core.cs +++ b/Core/Core.cs @@ -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); } diff --git a/Core/Startup.cs b/Core/Startup.cs index b8e20e0..f55e59c 100644 --- a/Core/Startup.cs +++ b/Core/Startup.cs @@ -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); + foreach (var module in _core.Modules) services.AddSingleton(module.GetType(), module); + // Trigger module handlers. _core.Modules.ConfigureServices(services); } diff --git a/modules/CombotAntiSpam/Startup.cs b/modules/CombotAntiSpam/CombotAntiSpam.cs similarity index 76% rename from modules/CombotAntiSpam/Startup.cs rename to modules/CombotAntiSpam/CombotAntiSpam.cs index 9879731..95fc214 100644 --- a/modules/CombotAntiSpam/Startup.cs +++ b/modules/CombotAntiSpam/CombotAntiSpam.cs @@ -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(); - } - } -} +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(); + } + } +} diff --git a/modules/RichSiteSummary/Startup.cs b/modules/RichSiteSummary/RichSiteSummary.cs similarity index 89% rename from modules/RichSiteSummary/Startup.cs rename to modules/RichSiteSummary/RichSiteSummary.cs index a309818..e902626 100644 --- a/modules/RichSiteSummary/Startup.cs +++ b/modules/RichSiteSummary/RichSiteSummary.cs @@ -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(options => - options.UseLazyLoadingProxies() - .UseMySql(Configuration.GetConnectionString("RichSiteSummary"))); - - services.AddTelegramBotParameterParser>() - .AddTelegramBotParameterParser>() - .AddTelegramBotParameterParser>(); - - services.AddQueue() - .AddQueue(); - - services.AddHostedService(); - } - } +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(options => + options.UseLazyLoadingProxies() + .UseMySql(Configuration.GetConnectionString("RichSiteSummary"))); + + services.AddTelegramBotParameterParser>() + .AddTelegramBotParameterParser>() + .AddTelegramBotParameterParser>(); + + services.AddQueue() + .AddQueue(); + + services.AddHostedService(); + } + } } \ No newline at end of file diff --git a/modules/RichSiteSummary/RichSiteSummaryRepositoryExtension.cs b/modules/RichSiteSummary/RichSiteSummaryRepositoryExtension.cs index d208968..ea1d539 100644 --- a/modules/RichSiteSummary/RichSiteSummaryRepositoryExtension.cs +++ b/modules/RichSiteSummary/RichSiteSummaryRepositoryExtension.cs @@ -7,7 +7,7 @@ using Telegram.Bot.Types; namespace Kruzya.TelegramBot.RichSiteSummary { - public static class RichSiteSummaryRepositoryExtension + internal static class RichSiteSummaryRepositoryExtension { #region Subscriber