Add an IServiceCollection extensions

This commit is contained in:
Ryan Nowak 2015-06-10 12:52:20 -07:00
Родитель e789e82d3d
Коммит 355a2b0a78
2 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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<IClaimUidExtractor, DefaultClaimUidExtractor>());
services.TryAdd(ServiceDescriptor.Singleton<Antiforgery, Antiforgery>());
services.TryAdd(
ServiceDescriptor.Singleton<IAntiforgeryAdditionalDataProvider, DefaultAntiforgeryAdditionalDataProvider>());
return services;
}
public static IServiceCollection ConfigureAntiforgery(
[NotNull] this IServiceCollection services,
[NotNull] Action<AntiforgeryOptions> setupAction)
{
services.Configure(setupAction);
return services;
}
}
}