using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Threading; using System.Threading.Tasks; namespace Kruzya.TelegramBot.Core; public abstract class Module { protected readonly Core Core; protected IConfiguration Configuration => Core.Configuration; public Module(Core core) { Core = core; } public virtual void ConfigureServices(IServiceCollection services) { } public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env) { } public virtual Task StartAsync(CancellationToken cts, IServiceScope scope) => Task.CompletedTask; public virtual Task StopAsync(CancellationToken cts, IServiceScope scope) => Task.CompletedTask; /// /// Ensures if module is loaded and started. Note that call can change module event chain. /// /// The Module type. /// Module instance. protected T EnsureLoaded() where T : Module { return (T) Core.EnsureLoaded(typeof(T)); } }