39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
// 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 System.Globalization;
|
|
using Microsoft.AspNet.Localization;
|
|
|
|
namespace Microsoft.AspNet.Builder
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for adding the <see cref="RequestLocalizationMiddleware"/> to an application.
|
|
/// </summary>
|
|
public static class ApplicationBuilderExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds the <see cref="RequestLocalizationMiddleware"/> to automatically set culture information for
|
|
/// requests based on information provided by the client.
|
|
/// </summary>
|
|
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
|
|
/// <param name="options">The options to configure the middleware with.</param>
|
|
/// <returns>The <see cref="IApplicationBuilder"/>.</returns>
|
|
public static IApplicationBuilder UseRequestLocalization(
|
|
this IApplicationBuilder app,
|
|
RequestLocalizationOptions options)
|
|
{
|
|
if (app == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(app));
|
|
}
|
|
|
|
if (options == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(options));
|
|
}
|
|
|
|
return app.UseMiddleware<RequestLocalizationMiddleware>(options);
|
|
}
|
|
}
|
|
} |