Skip to content

Commit

Permalink
Move MVC factory registration into MVC-specific extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang committed Mar 15, 2021
1 parent 92268f5 commit 9c2443b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/ProblemDetails/Mvc/MvcBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using MvcProblemDetailsFactory = Microsoft.AspNetCore.Mvc.Infrastructure.ProblemDetailsFactory;

namespace Hellang.Middleware.ProblemDetails.Mvc
{
Expand All @@ -18,6 +19,9 @@ public static class MvcBuilderExtensions
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddProblemDetailsConventions(this IMvcBuilder builder)
{
// Forward the MVC problem details factory registration to the factory used by the middleware.
builder.Services.TryAddSingleton<MvcProblemDetailsFactory>(p => p.GetRequiredService<ProblemDetailsFactory>());

builder.Services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<ApiBehaviorOptions>, ProblemDetailsApiBehaviorOptionsSetup>());

Expand Down
2 changes: 0 additions & 2 deletions src/ProblemDetails/ProblemDetailsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using MvcProblemDetailsFactory = Microsoft.AspNetCore.Mvc.Infrastructure.ProblemDetailsFactory;

namespace Hellang.Middleware.ProblemDetails
{
Expand Down Expand Up @@ -33,7 +32,6 @@ public static IServiceCollection AddProblemDetails(this IServiceCollection servi
}

services.TryAddSingleton<ProblemDetailsFactory>();
services.TryAddSingleton<MvcProblemDetailsFactory>(p => p.GetRequiredService<ProblemDetailsFactory>());
services.TryAddSingleton<ProblemDetailsMarkerService, ProblemDetailsMarkerService>();
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<ProblemDetailsOptions>, ProblemDetailsOptionsSetup>());

Expand Down

0 comments on commit 9c2443b

Please sign in to comment.