-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
Conflict.cs
56 lines (45 loc) · 1.94 KB
/
Conflict.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
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Http.HttpResults;
/// <summary>
/// An <see cref="IResult"/> that on execution will write an object to the response
/// with Conflict (409) status code.
/// </summary>
public sealed class Conflict : IResult, IEndpointMetadataProvider, IStatusCodeHttpResult
{
/// <summary>
/// Initializes a new instance of the <see cref="Conflict"/> class with the values
/// provided.
/// </summary>
internal Conflict()
{
}
/// <summary>
/// Gets the HTTP status code: <see cref="StatusCodes.Status409Conflict"/>
/// </summary>
public int StatusCode => StatusCodes.Status409Conflict;
int? IStatusCodeHttpResult.StatusCode => StatusCode;
/// <inheritdoc/>
public Task ExecuteAsync(HttpContext httpContext)
{
ArgumentNullException.ThrowIfNull(httpContext);
// Creating the logger with a string to preserve the category after the refactoring.
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.ConflictObjectResult");
HttpResultsHelper.Log.WritingResultAsStatusCode(logger, StatusCode);
httpContext.Response.StatusCode = StatusCode;
return Task.CompletedTask;
}
/// <inheritdoc/>
static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, EndpointBuilder builder)
{
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);
builder.Metadata.Add(new ProducesResponseTypeMetadata(StatusCodes.Status409Conflict, typeof(void)));
}
}