Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (38 sloc)
1.58 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) Martin Costello, 2020. All rights reserved. | |
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | |
using System; | |
using System.ComponentModel; | |
using Microsoft.AspNetCore.Hosting; | |
namespace Microsoft.Extensions.DependencyInjection | |
{ | |
/// <summary> | |
/// A class containing extension methods for the <see cref="IWebHostBuilder"/> interface. This class cannot be inherited. | |
/// </summary> | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
public static class IWebHostBuilderExtensions | |
{ | |
/// <summary> | |
/// Configures an HTTP GET resource for obtaining valid antiforgery tokens. | |
/// </summary> | |
/// <param name="builder">The <see cref="IWebHostBuilder"/> to configure.</param> | |
/// <returns> | |
/// The <see cref="IWebHostBuilder"/> specified by <paramref name="builder"/>. | |
/// </returns> | |
/// <exception cref="ArgumentNullException"> | |
/// <paramref name="builder"/> is <see langword="null"/>. | |
/// </exception> | |
public static IWebHostBuilder ConfigureAntiforgeryTokenResource(this IWebHostBuilder builder) | |
{ | |
if (builder == null) | |
{ | |
throw new ArgumentNullException(nameof(builder)); | |
} | |
return builder.ConfigureServices((services) => | |
{ | |
services.AddControllers() | |
.AddApplicationPart(typeof(TodoApp.AntiforgeryTokenController).Assembly) | |
.AddControllersAsServices(); | |
}); | |
} | |
} | |
} |