2025-04-22 16:48:53 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
2025-04-22 18:07:47 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-04-22 16:48:53 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.Contracts
|
|
|
|
|
|
{
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
/// <typeparam name="TResult"></typeparam>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public Task<TResult> ExecuteAsync<TInput, TResult>(string type, TInput input)
|
2025-04-22 16:48:53 +08:00
|
|
|
|
{
|
2025-04-22 18:07:47 +08:00
|
|
|
|
var factory = _provider.GetRequiredService<Func<string, Type, Type, object>>();
|
|
|
|
|
|
var strategy = (IAnalysisStrategy<TInput, TResult>)factory(type, typeof(TInput), typeof(TResult));
|
|
|
|
|
|
return strategy.ExecuteAsync(input);
|
2025-04-22 16:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-22 18:07:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-22 16:48:53 +08:00
|
|
|
|
}
|