-
Notifications
You must be signed in to change notification settings - Fork 31
/
Handler.cs
43 lines (42 loc) · 1.52 KB
/
Handler.cs
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
using Aggregates;
using Aggregates.Domain;
using NServiceBus;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Example.Todo.Domain
{
public class Handler :
IHandleMessages<Commands.Add>,
IHandleMessages<Commands.Remove>,
IHandleMessages<Commands.MarkActive>,
IHandleMessages<Commands.MarkComplete>
{
public async Task Handle(Commands.Add command, IMessageHandlerContext ctx)
{
var task = await ctx.For<Todo>().New(command.TodoId).ConfigureAwait(false);
task.Add(command.Message);
}
public async Task Handle(Commands.Edit command, IMessageHandlerContext ctx)
{
var task = await ctx.For<Todo>().Get(command.TodoId).ConfigureAwait(false);
task.Edit(command.Message);
}
public async Task Handle(Commands.Remove command, IMessageHandlerContext ctx)
{
var task = await ctx.For<Todo>().Get(command.TodoId).ConfigureAwait(false);
task.Remove();
}
public async Task Handle(Commands.MarkActive command, IMessageHandlerContext ctx)
{
var task = await ctx.For<Todo>().Get(command.TodoId).ConfigureAwait(false);
task.MarkActive();
}
public async Task Handle(Commands.MarkComplete command, IMessageHandlerContext ctx)
{
var task = await ctx.For<Todo>().Get(command.TodoId).ConfigureAwait(false);
task.MarkComplete();
}
}
}