Updating to new options pattern

This commit is contained in:
John Luo 2016-01-05 18:05:43 -08:00
parent e91ce99c70
commit c59528e4f9
3 changed files with 25 additions and 3 deletions

View File

@ -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<SessionMiddleware>();
}
/// <summary>
/// Adds the <see cref="SessionMiddleware"/> to automatically enable session state for the application.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="options">The <see cref="SessionOptions"/>.</param>
/// <returns>The <see cref="IApplicationBuilder"/>.</returns>
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<SessionMiddleware>(Options.Create(options));
}
}
}

View File

@ -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
{
/// <summary>
/// Represents the session state options for the application.

View File

@ -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<ISessionStore, DistributedSessionStore>();
return services;
}