/
Endpoint.cs
39 lines (29 loc) · 1.13 KB
/
Endpoint.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
namespace MinimalEndpoints;
public abstract class Endpoint<TResponse> : EndpointBase, IEndpoint
{
public abstract string Pattern { get; }
public abstract HttpMethod Method { get; }
[HandlerMethod]
public abstract Task<TResponse> SendAsync(CancellationToken cancellationToken = default);
public Delegate Handler => HandlerCore;
protected virtual async Task<TResponse> HandlerCore(CancellationToken cancellationToken = default)
{
return await SendAsync(cancellationToken);
}
}
public abstract class Endpoint<TRequest, TResponse> : EndpointBase, IEndpoint
{
public abstract string Pattern { get; }
public abstract HttpMethod Method { get; }
[HandlerMethod]
public abstract Task<TResponse> SendAsync(TRequest request, CancellationToken cancellationToken = default);
public Delegate Handler => SendAsync;
}
public abstract class GetByIdEndpoint<TResponse, TKey> : Endpoint<TKey, TResponse>
{
public override HttpMethod Method => HttpMethod.Get;
}
public abstract class GetByIdEndpoint<TResponse> : Endpoint<int, TResponse>
{
public override HttpMethod Method => HttpMethod.Get;
}