* Fixed method handlers behaviour

This commit is contained in:
2025-08-02 03:19:52 +04:00
parent 16d11990ec
commit 8e0d271901
4 changed files with 24 additions and 5 deletions
@@ -70,6 +70,7 @@ namespace Telegrator.Hosting.Web
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy());
}
Services.AddSingleton<IConfigurationManager>(Configuration);
Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings));
return new TelegramBotWebHost(_innerBuilder, _handlers);
}
+1 -1
View File
@@ -47,7 +47,6 @@ namespace Telegrator.Hosting
{
_innerBuilder = hostApplicationBuilder;
_settings = settings ?? new TelegramBotHostBuilderSettings();
_handlers = new HostHandlersCollection(Services, _settings);
_innerBuilder.Logging.ClearProviders();
@@ -78,6 +77,7 @@ namespace Telegrator.Hosting
}
Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings));
Services.AddSingleton<IConfigurationManager>(Configuration);
return new TelegramBotHost(_innerBuilder, _handlers);
}
}
+8
View File
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.Analyzers", "Tel
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.Hosting.Web", "Telegrator.Hosting.Web\Telegrator.Hosting.Web.csproj", "{98AB490F-6A36-CCFF-F6E6-B029D1665965}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SosalBot", "..\SosalBot\SosalBot\SosalBot.csproj", "{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AnalyzersDebug|Any CPU = AnalyzersDebug|Any CPU
@@ -63,6 +65,12 @@ Global
{98AB490F-6A36-CCFF-F6E6-B029D1665965}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98AB490F-6A36-CCFF-F6E6-B029D1665965}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98AB490F-6A36-CCFF-F6E6-B029D1665965}.Release|Any CPU.Build.0 = Release|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.AnalyzersDebug|Any CPU.ActiveCfg = Release|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.AnalyzersDebug|Any CPU.Build.0 = Release|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6AA4D47-0DCE-520E-5779-A14EA9CB1DEC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -15,6 +15,8 @@ namespace Telegrator.MadiatorCore.Descriptors
/// <typeparam name="TUpdate"></typeparam>
public class MethodHandlerDescriptor<TUpdate> : HandlerDescriptor where TUpdate : class
{
private readonly MethodInfo Method;
/// <summary>
/// Initializes new instance of <see cref="MethodHandlerDescriptor{TUpdate}"/>
/// </summary>
@@ -28,13 +30,21 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = handlerAttribute.Type;
Indexer = handlerAttribute.GetIndexer();
Filters = new DescriptorFiltersSet(handlerAttribute, stateKeeperAttribute, filters);
DisplayString = HandlerInspector.GetDisplayName(action.Method);
InstanceFactory = () => new MethodHandler(action.Method, UpdateType);
DisplayString = HandlerInspector.GetDisplayName(action.Method) ?? action.Method.Name;
Method = action.Method;
InstanceFactory = () => new MethodHandler(UpdateType);
LazyInitialization = handler =>
{
if (handler is not MethodHandler methodHandler)
throw new InvalidDataException();
methodHandler.Method = Method;
};
}
private class MethodHandler(MethodInfo method, UpdateType updateType) : AbstractUpdateHandler<TUpdate>(updateType)
private class MethodHandler(UpdateType updateType) : AbstractUpdateHandler<TUpdate>(updateType)
{
private readonly MethodInfo Method = method;
internal MethodInfo Method = null!;
public override async Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
{