-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandler.snippet
88 lines (78 loc) · 3.06 KB
/
Handler.snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Command Handler</Title>
<Author>Christian K</Author>
<Shortcut>chandler</Shortcut>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[
public class Command : IRequest
{
}
public class Handler : IRequestHandler<Command>
{
private readonly DataContext _context;
public Handler(DataContext context)
{
_context = context;
}
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
{
// handler logics here
var success = await _context.SaveChangesAsync() > 0; //this will true if > 0
if(success) return Unit.Value;
throw new Exception("Problem saving changes");
}
}
]]>
</Code>
<Imports>
<Import>
<Namespace>System.Threading</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
<Namespace>Domain</Namespace>
<Namespace>MediatR</Namespace>
<Namespace>Microsoft.EntityFrameworkCore</Namespace>
<Namespace>Persistence</Namespace>
</Import>
</Imports>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>Query Handler</Title>
<Author>Christian K</Author>
<Shortcut>qhandler</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>ReturnObject</ID>
<ToolTip>Add your return object.</ToolTip>
<Default>MyObj</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
public class Query : IRequest<$ReturnObject$>
{
}
public class Handler : IRequestHandler<Query, $ReturnObject$>
{
private readonly DataContext _context;
public Handler(DataContext context)
{
_context = context;
}
public async Task<$ReturnObject$> Handle(Query request, CancellationToken cancellationToken)
{
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>