mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
920148e05b
ISerializationBinder is added only in whitelist mode. Types for whitelisting should be registered manually via new API `Module.StartAsync()` or attribute `AllowedSerializableType(name)`
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// Ensures if module is loaded and started. Note that call can change module event chain.
|
|
/// </summary>
|
|
/// <typeparam name="T">The Module type.</typeparam>
|
|
/// <returns>Module instance.</returns>
|
|
protected T EnsureLoaded<T>() where T : Module
|
|
{
|
|
return (T) Core.EnsureLoaded(typeof(T));
|
|
}
|
|
} |