// 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.AspNet.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 . public static IServiceCollection AddSession(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddOptions(); services.AddTransient(); return services; } /// /// Adds services required for application session state. /// /// The to add the services to. /// The session options to configure the middleware with. /// The . public static IServiceCollection AddSession(this IServiceCollection services, Action configure) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.Configure(configure); return services.AddSession(); } } }