* Implemented IDisposable interface for handlers and added virtual method if such needed
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Telegrator.Handlers.Components
|
||||
/// <summary>
|
||||
/// Base class for update handlers, providing execution and lifetime management for Telegram updates.
|
||||
/// </summary>
|
||||
public abstract class UpdateHandlerBase(UpdateType handlingUpdateType)
|
||||
public abstract class UpdateHandlerBase(UpdateType handlingUpdateType) : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="UpdateType"/> that this handler processes.
|
||||
@@ -101,6 +101,16 @@ namespace Telegrator.Handlers.Components
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
protected abstract Task<Result> ExecuteInternal(IHandlerContainer container, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Dispose resources of this handler. Override if needed
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
/// <returns>Return <see langword="true"/> if dispose was successfull and garbage collecting for this object can be supressed</returns>
|
||||
protected virtual bool Dispose(bool disposing)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles failed filters during handler describing.
|
||||
/// Use <see cref="Result"/> to control how router should treat this fail.
|
||||
@@ -115,5 +125,15 @@ namespace Telegrator.Handlers.Components
|
||||
{
|
||||
return Task.FromResult(Result.Ok());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
if (LifetimeToken.IsEnded)
|
||||
return;
|
||||
|
||||
if (Dispose(true))
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user