Remove ConfigureDefaultOptions
This commit is contained in:
parent
9698f539f0
commit
300d69e644
|
|
@ -4,8 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Options.Infrastructure;
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.DependencyInjection
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +28,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.TryAddSingleton<IClaimsTransformation, NoopClaimsTransformation>(); // Can be replaced with scoped ones that use DbContext
|
services.TryAddSingleton<IClaimsTransformation, NoopClaimsTransformation>(); // Can be replaced with scoped ones that use DbContext
|
||||||
services.TryAddScoped<IAuthenticationHandlerProvider, AuthenticationHandlerProvider>();
|
services.TryAddScoped<IAuthenticationHandlerProvider, AuthenticationHandlerProvider>();
|
||||||
services.TryAddSingleton<IAuthenticationSchemeProvider, AuthenticationSchemeProvider>();
|
services.TryAddSingleton<IAuthenticationSchemeProvider, AuthenticationSchemeProvider>();
|
||||||
services.AddTransient<ConfigureDefaultOptions<AuthenticationOptions>, DefaultConfigureOptions>();
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,13 +52,5 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.Configure(configureOptions);
|
services.Configure(configureOptions);
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DefaultConfigureOptions : ConfigureDefaultOptions<AuthenticationOptions>
|
|
||||||
{
|
|
||||||
public DefaultConfigureOptions(IConfiguration config) :
|
|
||||||
base(options => config.GetSection("Microsoft:AspNetCore:Authentication").Bind(options))
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.Abstractions\Microsoft.AspNetCore.Authentication.Abstractions.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.Abstractions\Microsoft.AspNetCore.Authentication.Abstractions.csproj" />
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Http\Microsoft.AspNetCore.Http.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Http\Microsoft.AspNetCore.Http.csproj" />
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Http.Extensions\Microsoft.AspNetCore.Http.Extensions.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Http.Extensions\Microsoft.AspNetCore.Http.Extensions.csproj" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
// 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.Collections.Generic;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.Extensions.Options.Infrastructure;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Authentication
|
|
||||||
{
|
|
||||||
public class ConfigTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void AddCanBindAgainstDefaultConfig()
|
|
||||||
{
|
|
||||||
var dic = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{"Microsoft:AspNetCore:Authentication:DefaultSignInScheme", "<signin>"},
|
|
||||||
{"Microsoft:AspNetCore:Authentication:DefaultAuthenticateScheme", "<auth>"},
|
|
||||||
{"Microsoft:AspNetCore:Authentication:DefaultChallengeScheme", "<challenge>"}
|
|
||||||
};
|
|
||||||
var configurationBuilder = new ConfigurationBuilder();
|
|
||||||
configurationBuilder.AddInMemoryCollection(dic);
|
|
||||||
var config = configurationBuilder.Build();
|
|
||||||
var services = new ServiceCollection()
|
|
||||||
.AddOptions()
|
|
||||||
.AddSingleton<IConfigureOptions<AuthenticationOptions>, ConfigureDefaults<AuthenticationOptions>>()
|
|
||||||
.AddAuthenticationCore()
|
|
||||||
.AddSingleton<IConfiguration>(config);
|
|
||||||
var sp = services.BuildServiceProvider();
|
|
||||||
|
|
||||||
var options = sp.GetRequiredService<IOptions<AuthenticationOptions>>().Value;
|
|
||||||
Assert.Equal("<auth>", options.DefaultAuthenticateScheme);
|
|
||||||
Assert.Equal("<challenge>", options.DefaultChallengeScheme);
|
|
||||||
Assert.Equal("<signin>", options.DefaultSignInScheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue