// 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.Builder; using Microsoft.AspNetCore.Session; namespace Microsoft.Extensions.DependencyInjection { /// /// Extension methods for adding session services to the DI container. /// public static class SessionServiceCollectionExtensions { /// /// Adds services required for application session state. /// /// The to add the services to. /// The so that additional calls can be chained. public static IServiceCollection AddSession(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddTransient(); services.AddDataProtection(); return services; } /// /// Adds services required for application session state. /// /// The to add the services to. /// The session options to configure the middleware with. /// The so that additional calls can be chained. public static IServiceCollection AddSession(this IServiceCollection services, Action configure) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } services.Configure(configure); services.AddSession(); return services; } } }