mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 移除了 ContextAwareCommandExtensions 中废弃的 SendCommand 同步方法 - 移除了 ContextAwareQueryExtensions 中废弃的 SendQuery 同步方法 - 简化了 ICommand 和 IQuery 的类型引用,移除冗长的命名空间前缀 - 保持了异步命令和查询方法的功能完整性
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using GFramework.Core.Abstractions.query;
|
|
using GFramework.Core.Abstractions.rule;
|
|
|
|
namespace GFramework.Core.extensions;
|
|
|
|
/// <summary>
|
|
/// 提供对 IContextAware 接口的查询执行扩展方法
|
|
/// </summary>
|
|
public static class ContextAwareQueryExtensions
|
|
{
|
|
/// <summary>
|
|
/// 发送一个查询请求
|
|
/// </summary>
|
|
/// <typeparam name="TResult">查询结果类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的查询</param>
|
|
/// <returns>查询结果</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static TResult SendQuery<TResult>(this IContextAware contextAware, IQuery<TResult> query)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return context.SendQuery(query);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 异步发送一个查询请求
|
|
/// </summary>
|
|
/// <typeparam name="TResult">查询结果类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的异步查询</param>
|
|
/// <returns>查询结果</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static async Task<TResult> SendQueryAsync<TResult>(this IContextAware contextAware,
|
|
IAsyncQuery<TResult> query)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return await context.SendQueryAsync(query);
|
|
}
|
|
} |