2025-04-25 14:23:06 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
2025-04-22 18:07:47 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-04-22 16:48:53 +08:00
|
|
|
|
|
2025-04-27 09:16:37 +08:00
|
|
|
|
namespace JiShe.CollectBus.Protocol
|
2025-04-22 16:48:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
2025-04-22 23:45:08 +08:00
|
|
|
|
public class AnalysisStrategyContext(IServiceProvider provider)
|
2025-04-22 16:48:53 +08:00
|
|
|
|
{
|
2025-04-22 23:45:08 +08:00
|
|
|
|
private readonly IServiceProvider _provider = provider;
|
2025-04-22 16:48:53 +08:00
|
|
|
|
|
2025-04-22 18:07:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行策略
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TInput"></typeparam>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <param name="input"></param>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
/// <param name="result"></param>
|
2025-04-22 18:07:47 +08:00
|
|
|
|
/// <returns></returns>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync<TInput>(string type, TInput input,Action<dynamic>? result=null)
|
2025-04-22 16:48:53 +08:00
|
|
|
|
{
|
2025-04-29 09:16:48 +08:00
|
|
|
|
var factory = _provider.GetRequiredService<Func<string, Type, object>>();
|
|
|
|
|
|
var strategy = (IAnalysisStrategy<TInput>)factory(type, typeof(TInput));
|
|
|
|
|
|
return await strategy.ExecuteAsync(input, result);
|
2025-04-22 16:48:53 +08:00
|
|
|
|
}
|
2025-04-22 18:07:47 +08:00
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
}
|
2025-04-22 16:48:53 +08:00
|
|
|
|
}
|