Use AddHttpContextAccessor method added in aspnet/HttpAbstractions#947

This commit is contained in:
Kristian Hellang 2017-10-02 19:57:01 +02:00 committed by Hao Kung
parent 700c2afc21
commit 8136fc5306
11 changed files with 13 additions and 13 deletions

View File

@ -100,7 +100,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient<SessionManager, SessionManager<TUser, TApplication>>();
services.AddTransient<SessionManager<TUser, TApplication>>();
services.AddTransient<IRedirectUriResolver, ClientApplicationValidator<TApplication>>();
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.Configure(configure);

View File

@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Identity.Test
/// <param name="context"></param>
protected override void SetupIdentityServices(IServiceCollection services, object context)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddIdentity<TUser, TRole>(options =>
{
options.Password.RequireDigit = false;

View File

@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Identity.Test
/// <param name="context"></param>
protected virtual IdentityBuilder SetupBuilder(IServiceCollection services, object context)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddDataProtection();
var builder = services.AddIdentityCore<TUser>(options =>
{

View File

@ -91,7 +91,7 @@ namespace Microsoft.Extensions.DependencyInjection
});
// Hosting doesn't add IHttpContextAccessor by default
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
// Identity services
services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>();
services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>();

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
public InMemoryEFUserStoreTestWithGenerics()
{
var services = new ServiceCollection();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddDbContext<InMemoryContextWithGenerics>(options => options.UseInMemoryDatabase("Scratch"));
_context = services.BuildServiceProvider().GetRequiredService<InMemoryContextWithGenerics>();
}

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
public static IServiceCollection CreateTestServices()
{
var services = new ServiceCollection();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddLogging();
services.AddIdentity<IdentityUser, IdentityRole>();
return services;

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
{
services = new ServiceCollection();
}
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddDbContext<TContext>(options => options.UseSqlServer(connectionString));
return services;
}

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
protected override void SetupIdentityServices(IServiceCollection services, object context)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddSingleton((TestDbContext)context);
services.AddLogging();
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
{
services = new ServiceCollection();
}
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddDbContext<TContext>(options => options.UseSqlServer(connectionString));
return services;
}

View File

@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Identity.Test
{
var services = new ServiceCollection()
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build())
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>()
.AddHttpContextAccessor()
.AddLogging();
services.AddIdentity<TestUser, TestRole>()
.AddUserStore<NoopUserStore>()

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Identity.Test
.AddSingleton<IConfiguration>(config)
.AddTransient<IUserStore<TestUser>, NoopUserStore>();
services.AddIdentity<TestUser, TestRole>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.AddLogging();
var manager = services.BuildServiceProvider().GetRequiredService<UserManager<TestUser>>();
Assert.NotNull(manager.PasswordHasher);
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Identity.Test
var services = new ServiceCollection()
.AddSingleton<IConfiguration>(config)
.AddTransient<IUserStore<TestUser>, NoopUserStore>()
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
.AddHttpContextAccessor();
services.AddLogging();
@ -1544,7 +1544,7 @@ namespace Microsoft.AspNetCore.Identity.Test
.AddLogging()
.AddSingleton<IdentityErrorDescriber>(describer)
.AddSingleton<IUserStore<TestUser>>(store.Object)
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
.AddHttpContextAccessor();
services.AddIdentity<TestUser, TestRole>();