Skip to content

Commit e0e750d

Browse files
committed
IQueryHandler & IQueryBus & QueryBus added
1 parent 9035829 commit e0e750d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Library/Query/IQueryBus.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Library.Query
2+
{
3+
public interface IQueryBus
4+
{
5+
Task<TResponse> Dispatch<TRequest, TResponse>(TRequest command);
6+
}
7+
}

Library/Query/IQueryHandler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Library.Query
2+
{
3+
public interface IQueryHandler<TRequest, TResponse>
4+
{
5+
Task<TResponse> Handle(TRequest command);
6+
}
7+
}

Library/Query/QueryBus.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace Library.Query
4+
{
5+
public class QueryBus : IQueryBus
6+
{
7+
private readonly IServiceProvider _provider;
8+
public QueryBus(IServiceProvider provider)
9+
{
10+
_provider = provider;
11+
}
12+
13+
public async Task<TResponse> Dispatch<TRequest, TResponse>(TRequest query)
14+
{
15+
var service = _provider.GetRequiredService(typeof(IQueryHandler<TRequest, TResponse>)) as IQueryHandler<TRequest, TResponse>;
16+
return await service.Handle(query);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)