From 355a2b0a783f7bd4539340792785ec5d2b3ca837 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 10 Jun 2015 12:52:20 -0700 Subject: [PATCH] Add an IServiceCollection extensions --- .../AntiforgeryOptions.cs | 1 - .../ServiceCollectionExtensions.cs | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Antiforgery/ServiceCollectionExtensions.cs diff --git a/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptions.cs b/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptions.cs index 50f8f42..6906c02 100644 --- a/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptions.cs +++ b/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptions.cs @@ -1,7 +1,6 @@ // 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.Framework.Internal; namespace Microsoft.AspNet.Antiforgery diff --git a/src/Microsoft.AspNet.Antiforgery/ServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Antiforgery/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..59c2789 --- /dev/null +++ b/src/Microsoft.AspNet.Antiforgery/ServiceCollectionExtensions.cs @@ -0,0 +1,31 @@ +// 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.Antiforgery; +using Microsoft.Framework.Internal; + +namespace Microsoft.Framework.DependencyInjection +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddAntiforgery([NotNull] this IServiceCollection services) + { + services.AddDataProtection(); + + services.TryAdd(ServiceDescriptor.Singleton()); + services.TryAdd(ServiceDescriptor.Singleton()); + services.TryAdd( + ServiceDescriptor.Singleton()); + return services; + } + + public static IServiceCollection ConfigureAntiforgery( + [NotNull] this IServiceCollection services, + [NotNull] Action setupAction) + { + services.Configure(setupAction); + return services; + } + } +}