-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePerson.cs
More file actions
52 lines (43 loc) · 1.4 KB
/
Copy pathCreatePerson.cs
File metadata and controls
52 lines (43 loc) · 1.4 KB
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
using System.Diagnostics;
using System.Runtime.CompilerServices;
using JasperFx.Core;
using Wolverine.Http;
namespace Wolverine.Middleware.Problems;
public record CreatePerson;
public record PersonCreated(Guid Id);
public record PersonCreatedResponse(Guid Id) : CreationResponse($"/people/{Id}");
public class CreatePersonHandler
{
[WolverinePost("/people")]
public (PersonCreatedResponse, IEnumerable<object> ) Handle(CreatePerson command)
{
var id = CombGuidIdGeneration.NewGuid();
return (
new PersonCreatedResponse(id),
new[] { new PersonCreated(id) }
);
}
}
public class PersonCreatedHandler
{
public void Handle(PersonCreated e) => Console.Out.WriteLine(e);
}
public static class StopwatchMiddleware2
{
// The Stopwatch being returned from this method will
// be passed back into the later method
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Stopwatch Before()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
return stopwatch;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Finally(Stopwatch stopwatch, ILogger logger, Envelope envelope)
{
stopwatch.Stop();
logger.LogDebug("Envelope {Id} / {MessageType} ran in {Duration} milliseconds",
envelope.Id, envelope.MessageType, stopwatch.ElapsedMilliseconds);
}
}