diff --git a/GFramework.Core.Abstractions/architecture/IArchitectureContext.cs b/GFramework.Core.Abstractions/architecture/IArchitectureContext.cs
index 286ee25..496d228 100644
--- a/GFramework.Core.Abstractions/architecture/IArchitectureContext.cs
+++ b/GFramework.Core.Abstractions/architecture/IArchitectureContext.cs
@@ -104,9 +104,9 @@ public interface IArchitectureContext
/// [Mediator] 发送查询的同步版本(不推荐,仅用于兼容性)
///
/// 查询响应类型
- /// 要发送的查询对象
+ /// 要发送的查询对象
/// 查询结果
- TResponse SendQuery(Mediator.IQuery command);
+ TResponse SendQuery(Mediator.IQuery query);
///
/// 异步发送一个查询请求
@@ -121,10 +121,10 @@ public interface IArchitectureContext
/// 通过Mediator模式发送查询请求,支持取消操作
///
/// 查询响应类型
- /// 要发送的查询对象
+ /// 要发送的查询对象
/// 取消令牌,用于取消操作
/// 包含查询结果的ValueTask
- ValueTask SendQueryAsync(Mediator.IQuery command,
+ ValueTask SendQueryAsync(Mediator.IQuery query,
CancellationToken cancellationToken = default);
///
@@ -199,20 +199,6 @@ public interface IArchitectureContext
IRequest command,
CancellationToken cancellationToken = default);
- ///
- /// 发送查询
- ///
- ValueTask QueryAsync(
- IRequest query,
- CancellationToken cancellationToken = default);
-
- ///
- /// 发布事件通知
- ///
- ValueTask PublishEventAsync(
- TNotification notification,
- CancellationToken cancellationToken = default)
- where TNotification : INotification;
///
/// 获取环境对象
diff --git a/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs b/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
index ccc30dd..3e607e8 100644
--- a/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
+++ b/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
@@ -288,13 +288,13 @@ public class TestArchitectureContextV3 : IArchitectureContext
throw new NotImplementedException();
}
- public ValueTask SendQueryAsync(Mediator.IQuery command,
+ public ValueTask SendQueryAsync(Mediator.IQuery query,
CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
- public TResponse SendQuery(Mediator.IQuery command)
+ public TResponse SendQuery(Mediator.IQuery query)
{
throw new NotImplementedException();
}
@@ -323,18 +323,6 @@ public class TestArchitectureContextV3 : IArchitectureContext
throw new NotImplementedException();
}
- public ValueTask QueryAsync(IRequest query,
- CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
-
- public ValueTask PublishEventAsync(TNotification notification,
- CancellationToken cancellationToken = default) where TNotification : INotification
- {
- throw new NotImplementedException();
- }
-
public void SendCommand(ICommand command)
{
}
@@ -368,6 +356,18 @@ public class TestArchitectureContextV3 : IArchitectureContext
{
return _environment;
}
+
+ public ValueTask QueryAsync(IRequest query,
+ CancellationToken cancellationToken = default)
+ {
+ throw new NotImplementedException();
+ }
+
+ public ValueTask PublishEventAsync(TNotification notification,
+ CancellationToken cancellationToken = default) where TNotification : INotification
+ {
+ throw new NotImplementedException();
+ }
}
#endregion
\ No newline at end of file
diff --git a/GFramework.Core.Tests/architecture/GameContextTests.cs b/GFramework.Core.Tests/architecture/GameContextTests.cs
index c7cb31b..92ee46b 100644
--- a/GFramework.Core.Tests/architecture/GameContextTests.cs
+++ b/GFramework.Core.Tests/architecture/GameContextTests.cs
@@ -357,13 +357,13 @@ public class TestArchitectureContext : IArchitectureContext
throw new NotImplementedException();
}
- public ValueTask SendQueryAsync(Mediator.IQuery command,
+ public ValueTask SendQueryAsync(Mediator.IQuery query,
CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
- public TResponse SendQuery(Mediator.IQuery command)
+ public TResponse SendQuery(Mediator.IQuery query)
{
throw new NotImplementedException();
}
@@ -392,18 +392,6 @@ public class TestArchitectureContext : IArchitectureContext
throw new NotImplementedException();
}
- public ValueTask QueryAsync(IRequest query,
- CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
-
- public ValueTask PublishEventAsync(TNotification notification,
- CancellationToken cancellationToken = default) where TNotification : INotification
- {
- throw new NotImplementedException();
- }
-
///
/// 发送命令
///
@@ -463,4 +451,16 @@ public class TestArchitectureContext : IArchitectureContext
{
return Environment;
}
+
+ public ValueTask QueryAsync(IRequest query,
+ CancellationToken cancellationToken = default)
+ {
+ throw new NotImplementedException();
+ }
+
+ public ValueTask PublishEventAsync(TNotification notification,
+ CancellationToken cancellationToken = default) where TNotification : INotification
+ {
+ throw new NotImplementedException();
+ }
}
\ No newline at end of file
diff --git a/GFramework.Core.Tests/mediator/MediatorComprehensiveTests.cs b/GFramework.Core.Tests/mediator/MediatorComprehensiveTests.cs
index 933ab85..771334a 100644
--- a/GFramework.Core.Tests/mediator/MediatorComprehensiveTests.cs
+++ b/GFramework.Core.Tests/mediator/MediatorComprehensiveTests.cs
@@ -150,27 +150,6 @@ public class MediatorComprehensiveTests
Assert.That(result, Is.EqualTo(42));
}
- [Test]
- public async Task QueryAsync_Should_ReturnResult_When_Query_IsValid()
- {
- var testQuery = new TestQuery { QueryResult = "test result" };
- var result = await _context!.QueryAsync(testQuery);
-
- Assert.That(result, Is.EqualTo("test result"));
- }
-
- [Test]
- public async Task PublishEventAsync_Should_PublishNotification_When_Notification_IsValid()
- {
- TestNotificationHandler.LastReceivedMessage = null;
- var testNotification = new TestNotification { Message = "test event" };
-
- await _context!.PublishEventAsync(testNotification);
- await Task.Delay(100);
-
- Assert.That(TestNotificationHandler.LastReceivedMessage, Is.EqualTo("test event"));
- }
-
[Test]
public void GetService_Should_Use_Cache()
{
@@ -290,21 +269,6 @@ public class MediatorComprehensiveTests
Assert.That(sharedData.Value, Is.EqualTo(30)); // 10 + 20
}
- [Test]
- public async Task Query_Caching_With_Mediator()
- {
- var cache = new Dictionary();
- var query1 = new TestCachingQuery { Key = "test1", Cache = cache };
- var query2 = new TestCachingQuery { Key = "test1", Cache = cache }; // 相同key
-
- var result1 = await _context!.QueryAsync(query1);
- var result2 = await _context.QueryAsync(query2);
-
- // 验证缓存生效(相同key返回相同结果)
- Assert.That(result1, Is.EqualTo(result2));
- Assert.That(cache.Count, Is.EqualTo(1)); // 只缓存了一次
- }
-
[Test]
public async Task Notification_Ordering_Should_Be_Preserved()
{
diff --git a/GFramework.Core/architecture/ArchitectureContext.cs b/GFramework.Core/architecture/ArchitectureContext.cs
index d0c51a9..0e3a4a3 100644
--- a/GFramework.Core/architecture/ArchitectureContext.cs
+++ b/GFramework.Core/architecture/ArchitectureContext.cs
@@ -166,29 +166,6 @@ public class ArchitectureContext(IIocContainer container) : IArchitectureContext
return await SendRequestAsync(command, cancellationToken);
}
- ///
- /// [扩展] 发送查询
- /// 语法糖,等同于 SendRequestAsync,语义更清晰
- ///
- public async ValueTask QueryAsync(
- IRequest query,
- CancellationToken cancellationToken = default)
- {
- return await SendRequestAsync(query, cancellationToken);
- }
-
- ///
- /// [扩展] 发布事件通知
- /// 语法糖,等同于 PublishAsync
- ///
- public async ValueTask PublishEventAsync(
- TNotification notification,
- CancellationToken cancellationToken = default)
- where TNotification : INotification
- {
- await PublishAsync(notification, cancellationToken);
- }
-
#endregion
#region Query Execution
@@ -211,11 +188,11 @@ public class ArchitectureContext(IIocContainer container) : IArchitectureContext
/// [Mediator] 发送查询的同步版本(不推荐,仅用于兼容性)
///
/// 查询响应类型
- /// 要发送的查询对象
+ /// 要发送的查询对象
/// 查询结果
- public TResponse SendQuery(Mediator.IQuery command)
+ public TResponse SendQuery(Mediator.IQuery query)
{
- return SendQueryAsync(command).AsTask().GetAwaiter().GetResult();
+ return SendQueryAsync(query).AsTask().GetAwaiter().GetResult();
}
///
@@ -237,19 +214,19 @@ public class ArchitectureContext(IIocContainer container) : IArchitectureContext
/// 通过Mediator模式发送查询请求,支持取消操作
///
/// 查询响应类型
- /// 要发送的查询对象
+ /// 要发送的查询对象
/// 取消令牌,用于取消操作
/// 包含查询结果的ValueTask
- public async ValueTask SendQueryAsync(Mediator.IQuery command,
+ public async ValueTask SendQueryAsync(Mediator.IQuery query,
CancellationToken cancellationToken = default)
{
- ArgumentNullException.ThrowIfNull(command);
+ ArgumentNullException.ThrowIfNull(query);
var sender = Sender;
if (sender == null)
throw new InvalidOperationException("Sender not registered.");
- return await sender.Send(command, cancellationToken);
+ return await sender.Send(query, cancellationToken);
}
#endregion
diff --git a/GFramework.Core/extensions/ContextAwareExtensions.cs b/GFramework.Core/extensions/ContextAwareExtensions.cs
index 52559da..50231df 100644
--- a/GFramework.Core/extensions/ContextAwareExtensions.cs
+++ b/GFramework.Core/extensions/ContextAwareExtensions.cs
@@ -456,43 +456,4 @@ public static class ContextAwareExtensions
var context = contextAware.GetContext();
return context.SendAsync(command, cancellationToken);
}
-
- ///
- /// 发送查询
- ///
- /// 响应类型
- /// 实现 IContextAware 接口的对象
- /// 要发送的查询
- /// 取消令牌
- /// 查询结果
- /// 当 contextAware 或 query 为 null 时抛出
- public static ValueTask QueryAsync(this IContextAware contextAware,
- IRequest query, CancellationToken cancellationToken = default)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(query);
-
- var context = contextAware.GetContext();
- return context.QueryAsync(query, cancellationToken);
- }
-
- ///
- /// 发布事件通知
- ///
- /// 通知类型
- /// 实现 IContextAware 接口的对象
- /// 要发布的通知
- /// 取消令牌
- /// 异步任务
- /// 当 contextAware 或 notification 为 null 时抛出
- public static ValueTask PublishEventAsync(this IContextAware contextAware,
- TNotification notification, CancellationToken cancellationToken = default)
- where TNotification : INotification
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(notification);
-
- var context = contextAware.GetContext();
- return context.PublishEventAsync(notification, cancellationToken);
- }
}
\ No newline at end of file
diff --git a/GFramework.Godot/coroutine/ContextAwareCoroutineExtensions.cs b/GFramework.Godot/coroutine/ContextAwareCoroutineExtensions.cs
index 7a1293a..451cf68 100644
--- a/GFramework.Godot/coroutine/ContextAwareCoroutineExtensions.cs
+++ b/GFramework.Godot/coroutine/ContextAwareCoroutineExtensions.cs
@@ -99,7 +99,7 @@ public static class ContextAwareCoroutineExtensions
CancellationToken cancellationToken = default)
{
return contextAware
- .PublishEventAsync(notification, cancellationToken)
+ .PublishAsync(notification, cancellationToken)
.AsTask()
.ToCoroutineEnumerator()
.RunCoroutine(segment, tag);