| | | 1 | | using ZhEaIsNsAaBn.Utilities.APIResponses; |
| | | 2 | | |
| | | 3 | | // ReSharper disable once CheckNamespace |
| | | 4 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 5 | | |
| | | 6 | | /// <summary>Registers the API response settings.</summary> |
| | | 7 | | public static class APIResponsesRegistration |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Registers <see cref="APIResponsesSettings"/> (as <c>IOptions</c>) so <c>ToAPI</c> results map error codes and ca |
| | | 11 | | /// HTTP statuses with the app's overrides. Without this call the built-in defaults apply. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="services">The service collection.</param> |
| | | 14 | | /// <param name="configure">Overrides, e.g. <c>s => s.MapCode( "PolicyExpired", HttpStatusCode.Gone )</c>.</param |
| | | 15 | | /// <returns>The service collection.</returns> |
| | | 16 | | /// <exception cref="ArgumentNullException"><paramref name="services"/> is <see langword="null"/>.</exception> |
| | | 17 | | public static IServiceCollection AddAPIResponses( this IServiceCollection services, Action<APIResponsesSettings>? co |
| | | 18 | | { |
| | 198 | 19 | | ArgumentNullException.ThrowIfNull( services ); |
| | | 20 | | |
| | 198 | 21 | | var options = services.AddOptions<APIResponsesSettings>(); |
| | | 22 | | |
| | 239 | 23 | | if ( configure is not null ) { options.Configure( configure ); } |
| | | 24 | | |
| | | 25 | | |
| | 198 | 26 | | return services; |
| | | 27 | | } |
| | | 28 | | } |