|
6 | 6 | using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
7 | 7 | using Microsoft.AspNetCore.Mvc.Infrastructure;
|
8 | 8 | using Microsoft.Extensions.DependencyInjection;
|
| 9 | +using Microsoft.Extensions.DependencyInjection.Extensions; |
9 | 10 | using Swashbuckle.AspNetCore.Swagger;
|
10 | 11 | using Swashbuckle.AspNetCore.SwaggerGen;
|
11 | 12 |
|
@@ -34,9 +35,9 @@ public static void AddOpenApi(this IServiceCollection services, IMvcCoreBuilder
|
34 | 35 |
|
35 | 36 | private static void AddCustomApiExplorer(IServiceCollection services, IMvcCoreBuilder mvcBuilder)
|
36 | 37 | {
|
37 |
| - services.AddSingleton<ResourceFieldValidationMetadataProvider>(); |
| 38 | + services.TryAddSingleton<ResourceFieldValidationMetadataProvider>(); |
38 | 39 |
|
39 |
| - services.AddSingleton<IApiDescriptionGroupCollectionProvider>(provider => |
| 40 | + services.TryAddSingleton<IApiDescriptionGroupCollectionProvider>(provider => |
40 | 41 | {
|
41 | 42 | var controllerResourceMapping = provider.GetRequiredService<IControllerResourceMapping>();
|
42 | 43 | var actionDescriptorCollectionProvider = provider.GetRequiredService<IActionDescriptorCollectionProvider>();
|
@@ -76,8 +77,8 @@ private static void AddSwaggerGenerator(IServiceScope scope, IServiceCollection
|
76 | 77 |
|
77 | 78 | private static void AddSchemaGenerator(IServiceCollection services)
|
78 | 79 | {
|
79 |
| - services.AddSingleton<SchemaGenerator>(); |
80 |
| - services.AddSingleton<ISchemaGenerator, JsonApiSchemaGenerator>(); |
| 80 | + services.TryAddSingleton<SchemaGenerator>(); |
| 81 | + services.TryAddSingleton<ISchemaGenerator, JsonApiSchemaGenerator>(); |
81 | 82 | }
|
82 | 83 |
|
83 | 84 | private static void SetOperationInfo(SwaggerGenOptions swaggerGenOptions, IControllerResourceMapping controllerResourceMapping,
|
@@ -114,10 +115,10 @@ private static void SetSchemaIdSelector(SwaggerGenOptions swaggerGenOptions, IRe
|
114 | 115 |
|
115 | 116 | private static void AddCustomSwaggerComponents(IServiceCollection services)
|
116 | 117 | {
|
117 |
| - services.AddSingleton<SwaggerGenerator>(); |
118 |
| - services.AddSingleton<ISwaggerProvider, CachingSwaggerGenerator>(); |
| 118 | + services.TryAddSingleton<SwaggerGenerator>(); |
| 119 | + services.TryAddSingleton<ISwaggerProvider, CachingSwaggerGenerator>(); |
119 | 120 |
|
120 |
| - services.AddSingleton<ISerializerDataContractResolver, JsonApiDataContractResolver>(); |
| 121 | + services.TryAddSingleton<ISerializerDataContractResolver, JsonApiDataContractResolver>(); |
121 | 122 | }
|
122 | 123 |
|
123 | 124 | private static void AddSwashbuckleCliCompatibility(IServiceScope scope, IMvcCoreBuilder mvcBuilder)
|
|
0 commit comments