* Added Result class to communicate with router from handler

* Removed "ExecuteOnlyFirstFoundHanlder" in sake of testing new Result pattern based routing system
* Removed obsolete option property "DescendDescriptorIndex"
* Changed router logic
* Changed handlers pool logic
This commit is contained in:
2025-08-02 02:32:38 +04:00
parent b8e4398b50
commit 16d11990ec
26 changed files with 347 additions and 115 deletions
@@ -118,13 +118,13 @@ namespace Telegrator.Handlers.Components
/// <param name="container">The handler container.</param>
/// <param name="cancellation">The cancellation token.</param>
/// <exception cref="Exception">Thrown when no branch method is set.</exception>
public override async Task Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
public override async Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
{
if (branchMethodInfo is null)
throw new Exception();
Cancellation = cancellation;
await BranchExecuteWrapper(container, branchMethodInfo);
return await BranchExecuteWrapper(container, branchMethodInfo);
}
/// <summary>
@@ -132,21 +132,20 @@ namespace Telegrator.Handlers.Components
/// </summary>
/// <param name="container">The handler container.</param>
/// <param name="methodInfo">The method to execute.</param>
protected virtual async Task BranchExecuteWrapper(IAbstractHandlerContainer<TUpdate> container, MethodInfo methodInfo)
protected virtual async Task<Result> BranchExecuteWrapper(IAbstractHandlerContainer<TUpdate> container, MethodInfo methodInfo)
{
if (methodInfo.ReturnType == typeof(void))
{
methodInfo.Invoke(this, []);
return;
return Result.Ok();
}
else
{
object branchReturn = methodInfo.Invoke(this, []);
if (branchReturn == null)
return;
if (branchReturn is Task branchTask)
await branchTask;
if (branchReturn is not Task<Result> branchTask)
throw new InvalidOperationException();
return await branchTask;
}
}