React to options
This commit is contained in:
Родитель
7bb59a287c
Коммит
f5c8bf09e2
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetlitedev/api/v2" />
|
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetlitedev/api/v2" />
|
||||||
|
|
|
@ -13,10 +13,8 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
public class AntiforgeryOptionsSetup : ConfigureOptions<AntiforgeryOptions>
|
public class AntiforgeryOptionsSetup : ConfigureOptions<AntiforgeryOptions>
|
||||||
{
|
{
|
||||||
public AntiforgeryOptionsSetup(IOptions<DataProtectionOptions> dataProtectionOptionsAccessor)
|
public AntiforgeryOptionsSetup(IOptions<DataProtectionOptions> 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)
|
public static void ConfigureOptions(AntiforgeryOptions options, DataProtectionOptions dataProtectionOptions)
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
IAntiforgeryTokenStore tokenStore,
|
IAntiforgeryTokenStore tokenStore,
|
||||||
IHtmlEncoder htmlEncoder)
|
IHtmlEncoder htmlEncoder)
|
||||||
{
|
{
|
||||||
_options = antiforgeryOptionsAccessor.Options;
|
_options = antiforgeryOptionsAccessor.Value;
|
||||||
_tokenGenerator = tokenGenerator;
|
_tokenGenerator = tokenGenerator;
|
||||||
_tokenSerializer = tokenSerializer;
|
_tokenSerializer = tokenSerializer;
|
||||||
_tokenStore = tokenStore;
|
_tokenStore = tokenStore;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
[NotNull] IOptions<AntiforgeryOptions> optionsAccessor,
|
[NotNull] IOptions<AntiforgeryOptions> optionsAccessor,
|
||||||
[NotNull] IAntiforgeryTokenSerializer tokenSerializer)
|
[NotNull] IAntiforgeryTokenSerializer tokenSerializer)
|
||||||
{
|
{
|
||||||
_options = optionsAccessor.Options;
|
_options = optionsAccessor.Value;
|
||||||
_tokenSerializer = tokenSerializer;
|
_tokenSerializer = tokenSerializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
var options = services.GetRequiredService<IOptions<AntiforgeryOptions>>();
|
var options = services.GetRequiredService<IOptions<AntiforgeryOptions>>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var cookieName = options.Options.CookieName;
|
var cookieName = options.Value.CookieName;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedCookieName, cookieName);
|
Assert.Equal(expectedCookieName, cookieName);
|
||||||
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
var options = services.GetRequiredService<IOptions<AntiforgeryOptions>>();
|
var options = services.GetRequiredService<IOptions<AntiforgeryOptions>>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var cookieName = options.Options.CookieName;
|
var cookieName = options.Value.CookieName;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("antiforgery", cookieName);
|
Assert.Equal("antiforgery", cookieName);
|
||||||
|
|
|
@ -466,7 +466,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
var optionsManager = new TestOptionsManager();
|
var optionsManager = new TestOptionsManager();
|
||||||
if (options != null)
|
if (options != null)
|
||||||
{
|
{
|
||||||
optionsManager.Options = options;
|
optionsManager.Value = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultAntiforgery(
|
return new DefaultAntiforgery(
|
||||||
|
@ -628,12 +628,7 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
|
|
||||||
private class TestOptionsManager : IOptions<AntiforgeryOptions>
|
private class TestOptionsManager : IOptions<AntiforgeryOptions>
|
||||||
{
|
{
|
||||||
public AntiforgeryOptions Options { get; set; } = new AntiforgeryOptions();
|
public AntiforgeryOptions Value { get; set; } = new AntiforgeryOptions();
|
||||||
|
|
||||||
public AntiforgeryOptions GetNamedOptions(string name)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,11 +17,6 @@ namespace Microsoft.AspNet.Antiforgery
|
||||||
Options = options;
|
Options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AntiforgeryOptions Options { get; set; } = new AntiforgeryOptions();
|
public AntiforgeryOptions Value { get; set; } = new AntiforgeryOptions();
|
||||||
|
|
||||||
public AntiforgeryOptions GetNamedOptions(string name)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче