diff --git a/src/Microsoft.AspNet.Session/SessionMiddlewareExtensions.cs b/src/Microsoft.AspNet.Session/SessionMiddlewareExtensions.cs index 96feb96721..08fea0017c 100644 --- a/src/Microsoft.AspNet.Session/SessionMiddlewareExtensions.cs +++ b/src/Microsoft.AspNet.Session/SessionMiddlewareExtensions.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNet.Session; +using Microsoft.Extensions.Options; namespace Microsoft.AspNet.Builder { @@ -25,5 +26,25 @@ namespace Microsoft.AspNet.Builder return app.UseMiddleware(); } + + /// + /// Adds the to automatically enable session state for the application. + /// + /// The . + /// The . + /// The . + public static IApplicationBuilder UseSession(this IApplicationBuilder app, SessionOptions options) + { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + return app.UseMiddleware(Options.Create(options)); + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Session/SessionOptions.cs b/src/Microsoft.AspNet.Session/SessionOptions.cs index edc83b2f93..2f6fe56d58 100644 --- a/src/Microsoft.AspNet.Session/SessionOptions.cs +++ b/src/Microsoft.AspNet.Session/SessionOptions.cs @@ -2,8 +2,9 @@ // 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.AspNet.Session +namespace Microsoft.AspNet.Builder { /// /// Represents the session state options for the application. diff --git a/src/Microsoft.AspNet.Session/SessionServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Session/SessionServiceCollectionExtensions.cs index 4f20017203..2abcd0d668 100644 --- a/src/Microsoft.AspNet.Session/SessionServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Session/SessionServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Session; namespace Microsoft.Extensions.DependencyInjection @@ -22,8 +23,7 @@ namespace Microsoft.Extensions.DependencyInjection { throw new ArgumentNullException(nameof(services)); } - - services.AddOptions(); + services.AddTransient(); return services; }