// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.ResponseCaching; using Microsoft.AspNetCore.ResponseCaching.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { /// /// Extension methods for the ResponseCaching middleware. /// public static class ResponseCachingServicesExtensions { /// /// Add response caching services. /// /// The for adding services. /// public static IServiceCollection AddResponseCaching(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddMemoryCache(); services.TryAdd(ServiceDescriptor.Singleton()); services.TryAdd(ServiceDescriptor.Singleton()); services.TryAdd(ServiceDescriptor.Singleton()); return services; } /// /// Add response caching services and configure the related options. /// /// The for adding services. /// A delegate to configure the . /// public static IServiceCollection AddResponseCaching(this IServiceCollection services, Action configureOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } services.Configure(configureOptions); services.AddResponseCaching(); return services; } } }