Files
telegram-bot/Core/Module.cs
CrazyHackGUT 920148e05b add Uri parser, add ISerializationBinder
ISerializationBinder is added only in whitelist mode. Types for whitelisting should be registered manually via new API `Module.StartAsync()` or attribute `AllowedSerializableType(name)`
2024-05-29 00:19:30 +03:00

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));
}
}