-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added helpers for commands, queries and event handlers.
Strengthen the API tests
- Loading branch information
1 parent
46fb028
commit eabdead
Showing
9 changed files
with
100 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Core.Commands | ||
{ | ||
public static class Config | ||
{ | ||
public static IServiceCollection AddCommandHandler<TCommand, TCommandHandler>( | ||
this IServiceCollection services | ||
) | ||
where TCommand : ICommand | ||
where TCommandHandler : class, ICommandHandler<TCommand> | ||
{ | ||
return services.AddTransient<TCommandHandler>() | ||
.AddTransient<IRequestHandler<TCommand, Unit>>(sp => sp.GetRequiredService<TCommandHandler>()) | ||
.AddTransient<ICommandHandler<TCommand>>(sp => sp.GetRequiredService<TCommandHandler>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Core.Events | ||
{ | ||
public static class Config | ||
{ | ||
public static IServiceCollection AddEventHandler<TEvent, TEventResult, TEventHandler>( | ||
this IServiceCollection services | ||
) | ||
where TEvent : IEvent | ||
where TEventHandler : class, IEventHandler<TEvent> | ||
{ | ||
return services.AddTransient<TEventHandler>() | ||
.AddTransient<INotificationHandler<TEvent>>(sp => sp.GetRequiredService<TEventHandler>()) | ||
.AddTransient<IEventHandler<TEvent>>(sp => sp.GetRequiredService<TEventHandler>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Core.Queries | ||
{ | ||
public static class Config | ||
{ | ||
public static IServiceCollection AddQueryHandler<TQuery, TQueryResult, TQueryHandler>( | ||
this IServiceCollection services | ||
) | ||
where TQuery : IQuery<TQueryResult> | ||
where TQueryHandler : class, IQueryHandler<TQuery, TQueryResult> | ||
{ | ||
return services.AddTransient<TQueryHandler>() | ||
.AddTransient<IRequestHandler<TQuery, TQueryResult>>(sp => sp.GetRequiredService<TQueryHandler>()) | ||
.AddTransient<IQueryHandler<TQuery, TQueryResult>>(sp => sp.GetRequiredService<TQueryHandler>()); | ||
} | ||
} | ||
} |