From f5c8bf09e2c7ec04443fa8fce6a1453c251fc7e4 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 2 Sep 2015 15:28:52 -0700 Subject: [PATCH] React to options --- NuGet.Config | 2 +- .../AntiforgeryOptionsSetup.cs | 4 +--- src/Microsoft.AspNet.Antiforgery/DefaultAntiforgery.cs | 2 +- .../DefaultAntiforgeryTokenStore.cs | 2 +- .../AntiforgeryOptionsSetupTest.cs | 4 ++-- .../DefaultAntiforgeryTest.cs | 9 ++------- .../TestOptionsManager.cs | 7 +------ 7 files changed, 9 insertions(+), 21 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 56d86ac..b20b733 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,4 +1,4 @@ - + diff --git a/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptionsSetup.cs b/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptionsSetup.cs index 7603066..f37c3e9 100644 --- a/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptionsSetup.cs +++ b/src/Microsoft.AspNet.Antiforgery/AntiforgeryOptionsSetup.cs @@ -13,10 +13,8 @@ namespace Microsoft.AspNet.Antiforgery public class AntiforgeryOptionsSetup : ConfigureOptions { public AntiforgeryOptionsSetup(IOptions dataProtectionOptionsAccessor) - : base((options) => ConfigureOptions(options, dataProtectionOptionsAccessor.Options)) + : base((options) => ConfigureOptions(options, dataProtectionOptionsAccessor.Value)) { - // We want this to run after any user setups to compute a default name if needed. - Order = 10000; } public static void ConfigureOptions(AntiforgeryOptions options, DataProtectionOptions dataProtectionOptions) diff --git a/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgery.cs b/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgery.cs index 18a11c7..b68ae09 100644 --- a/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgery.cs +++ b/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgery.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Antiforgery IAntiforgeryTokenStore tokenStore, IHtmlEncoder htmlEncoder) { - _options = antiforgeryOptionsAccessor.Options; + _options = antiforgeryOptionsAccessor.Value; _tokenGenerator = tokenGenerator; _tokenSerializer = tokenSerializer; _tokenStore = tokenStore; diff --git a/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgeryTokenStore.cs b/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgeryTokenStore.cs index a0fb208..cd0667f 100644 --- a/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgeryTokenStore.cs +++ b/src/Microsoft.AspNet.Antiforgery/DefaultAntiforgeryTokenStore.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Antiforgery [NotNull] IOptions optionsAccessor, [NotNull] IAntiforgeryTokenSerializer tokenSerializer) { - _options = optionsAccessor.Options; + _options = optionsAccessor.Value; _tokenSerializer = tokenSerializer; } diff --git a/test/Microsoft.AspNet.Antiforgery.Test/AntiforgeryOptionsSetupTest.cs b/test/Microsoft.AspNet.Antiforgery.Test/AntiforgeryOptionsSetupTest.cs index 68bd517..b3b9bc7 100644 --- a/test/Microsoft.AspNet.Antiforgery.Test/AntiforgeryOptionsSetupTest.cs +++ b/test/Microsoft.AspNet.Antiforgery.Test/AntiforgeryOptionsSetupTest.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Antiforgery var options = services.GetRequiredService>(); // Act - var cookieName = options.Options.CookieName; + var cookieName = options.Value.CookieName; // Assert Assert.Equal(expectedCookieName, cookieName); @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Antiforgery var options = services.GetRequiredService>(); // Act - var cookieName = options.Options.CookieName; + var cookieName = options.Value.CookieName; // Assert Assert.Equal("antiforgery", cookieName); diff --git a/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTest.cs b/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTest.cs index b283ee5..912bc01 100644 --- a/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTest.cs +++ b/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTest.cs @@ -466,7 +466,7 @@ namespace Microsoft.AspNet.Antiforgery var optionsManager = new TestOptionsManager(); if (options != null) { - optionsManager.Options = options; + optionsManager.Value = options; } return new DefaultAntiforgery( @@ -628,12 +628,7 @@ namespace Microsoft.AspNet.Antiforgery private class TestOptionsManager : IOptions { - public AntiforgeryOptions Options { get; set; } = new AntiforgeryOptions(); - - public AntiforgeryOptions GetNamedOptions(string name) - { - throw new NotImplementedException(); - } + public AntiforgeryOptions Value { get; set; } = new AntiforgeryOptions(); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Antiforgery.Test/TestOptionsManager.cs b/test/Microsoft.AspNet.Antiforgery.Test/TestOptionsManager.cs index 2a74d97..9df6d86 100644 --- a/test/Microsoft.AspNet.Antiforgery.Test/TestOptionsManager.cs +++ b/test/Microsoft.AspNet.Antiforgery.Test/TestOptionsManager.cs @@ -17,11 +17,6 @@ namespace Microsoft.AspNet.Antiforgery Options = options; } - public AntiforgeryOptions Options { get; set; } = new AntiforgeryOptions(); - - public AntiforgeryOptions GetNamedOptions(string name) - { - throw new NotImplementedException(); - } + public AntiforgeryOptions Value { get; set; } = new AntiforgeryOptions(); } }