Last active
February 4, 2025 23:40
-
-
Save jonsagara/70c63e20132d64c1d2418c5959560137 to your computer and use it in GitHub Desktop.
Inserts Query, Command, CommandResult, QueryHandler, and CommandHandler classes for MediatR 5.x. Save with the extension .snippet instead of .xml.
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<CodeSnippets | |
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>CreateMediatRClasses</Title> | |
<Author>Jon Sagara</Author> | |
<Description>Inserts Query, Command, and QueryHandler classes for MediatR</Description> | |
<Shortcut>mediator</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public class Query : IRequest<Command> | |
{ } | |
public class Command : IRequest<CommandResult> | |
{ } | |
public class CommandResult | |
{ | |
public List<(string, string)> Errors { get; private set; } = []; | |
} | |
public class QueryHandler : IRequestHandler<Query, Command> | |
{ | |
public QueryHandler() | |
{ | |
} | |
public async Task<Command> Handle(Query request, CancellationToken cancellationToken) | |
{ | |
var command = new Command(); | |
await Task.CompletedTask; | |
return command; | |
} | |
} | |
public class CommandHandler : IRequestHandler<Command, CommandResult> | |
{ | |
public CommandHandler() | |
{ | |
} | |
public async Task<CommandResult> Handle(Command request, CancellationToken cancellationToken) | |
{ | |
var result = new CommandResult(); | |
await Task.CompletedTask; | |
return result; | |
} | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to support changes in MediatR 4.0