Last active
August 13, 2023 09:16
-
-
Save msmolcic/023ef30250fcc8a9bad168ecb64c13a7 to your computer and use it in GitHub Desktop.
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
How to use? | |
0. Review the content of the files, never trust custom code on the Internet. | |
1. Download the .snippet files below. | |
2. Import them to Visual Studio. | |
3. Enjoy! |
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>MediatR Command</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR command.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mcmd</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $CommandName$ | |
{ | |
public sealed record Command() : IRequest<Unit>; | |
public sealed class CommandHandler : IRequestHandler<Command, Unit> | |
{ | |
public CommandHandler() | |
{ | |
} | |
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | |
{ | |
$end$ | |
return Unit.Value; | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>CommandName</ID> | |
<ToolTip>Name of the command.</ToolTip> | |
<Default>NewCommand</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
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>MediatR Command With Result</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR command with result.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mcmdr</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $CommandName$ | |
{ | |
public sealed record Command() : IRequest<$ResultType$>; | |
public sealed class CommandHandler : IRequestHandler<Command, $ResultType$> | |
{ | |
public CommandHandler() | |
{ | |
} | |
public async Task<$ResultType$> Handle(Command command, CancellationToken cancellationToken) | |
{ | |
$end$ | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>CommandName</ID> | |
<ToolTip>Name of the command.</ToolTip> | |
<Default>NewCommand</Default> | |
</Literal> | |
<Literal> | |
<ID>ResultType</ID> | |
<ToolTip>Type of the result.</ToolTip> | |
<Default>Result</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
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>MediatR Command With Validation</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR command with validation.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mcmdv</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $CommandName$ | |
{ | |
public sealed record Command() : IRequest<Unit>; | |
public sealed class CommandValidator : AbstractValidator<Command> | |
{ | |
public CommandValidator() | |
{ | |
} | |
} | |
public sealed class CommandHandler : IRequestHandler<Command, Unit> | |
{ | |
public CommandHandler() | |
{ | |
} | |
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | |
{ | |
$end$ | |
return Unit.Value; | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>CommandName</ID> | |
<ToolTip>Name of the command.</ToolTip> | |
<Default>NewCommand</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>FluentValidation</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
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>MediatR Command With Validation And Result</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR command with validation and result.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mcmdvr</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $CommandName$ | |
{ | |
public sealed record Command() : IRequest<$ResultType$>; | |
public sealed class CommandValidator : AbstractValidator<Command> | |
{ | |
public CommandValidator() | |
{ | |
} | |
} | |
public sealed class CommandHandler : IRequestHandler<Command, $ResultType$> | |
{ | |
public CommandHandler() | |
{ | |
} | |
public async Task<$ResultType$> Handle(Command command, CancellationToken cancellationToken) | |
{ | |
$end$ | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>CommandName</ID> | |
<ToolTip>Name of the command.</ToolTip> | |
<Default>NewCommand</Default> | |
</Literal> | |
<Literal> | |
<ID>ResultType</ID> | |
<ToolTip>Type of the result.</ToolTip> | |
<Default>Result</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>FluentValidation</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
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>MediatR Query</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR query.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mqry</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $QueryName$ | |
{ | |
public sealed record Query() : IRequest<$ResultType$>; | |
public sealed class QueryHandler : IRequestHandler<Query, $ResultType$> | |
{ | |
public QueryHandler() | |
{ | |
} | |
public async Task<$ResultType$> Handle(Query query, CancellationToken cancellationToken) | |
{ | |
$end$ | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>QueryName</ID> | |
<ToolTip>Name of the query.</ToolTip> | |
<Default>NewQuery</Default> | |
</Literal> | |
<Literal> | |
<ID>ResultType</ID> | |
<ToolTip>Type of the result.</ToolTip> | |
<Default>Result</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
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>MediatR Query With Validation</Title> | |
<Author>Mario Smolcic</Author> | |
<Description>Creates a new MediatR query with validation.</Description> | |
<HelpUrl>www.codecrafting.tips</HelpUrl> | |
<Shortcut>mqryv</Shortcut> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[public static class $QueryName$ | |
{ | |
public sealed record Query() : IRequest<$ResultType$>; | |
public sealed class QueryValidator : AbstractValidator<Query> | |
{ | |
public QueryValidator() | |
{ | |
} | |
} | |
public sealed class QueryHandler : IRequestHandler<Query, $ResultType$> | |
{ | |
public QueryHandler() | |
{ | |
} | |
public async Task<$ResultType$> Handle(Query query, CancellationToken cancellationToken) | |
{ | |
$end$ | |
} | |
} | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal> | |
<ID>QueryName</ID> | |
<ToolTip>Name of the query.</ToolTip> | |
<Default>NewQuery</Default> | |
</Literal> | |
<Literal> | |
<ID>ResultType</ID> | |
<ToolTip>Type of the result.</ToolTip> | |
<Default>Result</Default> | |
</Literal> | |
</Declarations> | |
<Imports> | |
<Import> | |
<Namespace>System.Threading</Namespace> | |
</Import> | |
<Import> | |
<Namespace>System.Threading.Tasks</Namespace> | |
</Import> | |
<Import> | |
<Namespace>FluentValidation</Namespace> | |
</Import> | |
<Import> | |
<Namespace>MediatR</Namespace> | |
</Import> | |
</Imports> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment