Skip to content

Commit cdcd5c6

Browse files
committed
add query interface;
1 parent c641fab commit cdcd5c6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/CodeWF.EventBus/EventBus.Publish.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public void Publish<TCommand>(TCommand command) where TCommand : Command
1111
PublishAsync(command).GetAwaiter().GetResult();
1212
}
1313

14+
public T Query<T>(Query<T> query)
15+
{
16+
Publish(query);
17+
return query.Result;
18+
}
19+
1420
public async Task PublishAsync<TCommand>(TCommand command) where TCommand : Command
1521
{
1622
if (_subscriptions.TryGetValue(typeof(TCommand), out var handlers))
@@ -28,5 +34,11 @@ public async Task PublishAsync<TCommand>(TCommand command) where TCommand : Comm
2834
}
2935
}
3036
}
37+
38+
public async Task<T> QueryAsync<T>(Query<T> query)
39+
{
40+
await PublishAsync(query);
41+
return query.Result;
42+
}
3143
}
3244
}

src/CodeWF.EventBus/IEventBus.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface IEventBus
1515
void Unsubscribe<TCommand>(Action<TCommand> action) where TCommand : Command;
1616
void Unsubscribe<TCommand>(Func<TCommand, Task> asyncAction) where TCommand : Command;
1717
void Publish<TCommand>(TCommand command) where TCommand : Command;
18+
T Query<T>(Query<T> query);
1819
Task PublishAsync<TCommand>(TCommand command) where TCommand : Command;
20+
Task<T> QueryAsync<T>(Query<T> query);
1921
}
2022
}

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory).vs\$(SolutionName)\Intermediate\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
44
<OutputPath>$(MSBuildThisFileDirectory)\Output\</OutputPath>
55
<AppendTargetFrameworkToOutputPath>True</AppendTargetFrameworkToOutputPath>
6-
<Version>3.3.1</Version>
6+
<Version>3.4.0</Version>
77
</PropertyGroup>
88
</Project>

0 commit comments

Comments
 (0)