diff --git a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs index 1e1b171cf6..cae46da8d1 100644 --- a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs @@ -100,7 +100,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient>(); services.AddTransient>(); services.AddTransient>(); - services.TryAddSingleton(); + services.AddHttpContextAccessor(); services.Configure(configure); diff --git a/src/Microsoft.AspNetCore.Identity.Specification.Tests/IdentitySpecificationTestBase.cs b/src/Microsoft.AspNetCore.Identity.Specification.Tests/IdentitySpecificationTestBase.cs index bf7d0c9304..9d43420682 100644 --- a/src/Microsoft.AspNetCore.Identity.Specification.Tests/IdentitySpecificationTestBase.cs +++ b/src/Microsoft.AspNetCore.Identity.Specification.Tests/IdentitySpecificationTestBase.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Identity.Test /// protected override void SetupIdentityServices(IServiceCollection services, object context) { - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddIdentity(options => { options.Password.RequireDigit = false; diff --git a/src/Microsoft.AspNetCore.Identity.Specification.Tests/UserManagerSpecificationTests.cs b/src/Microsoft.AspNetCore.Identity.Specification.Tests/UserManagerSpecificationTests.cs index 4d36802f4f..dd9c4c427b 100644 --- a/src/Microsoft.AspNetCore.Identity.Specification.Tests/UserManagerSpecificationTests.cs +++ b/src/Microsoft.AspNetCore.Identity.Specification.Tests/UserManagerSpecificationTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Identity.Test /// protected virtual IdentityBuilder SetupBuilder(IServiceCollection services, object context) { - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddDataProtection(); var builder = services.AddIdentityCore(options => { diff --git a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs index acd9114505..014b176d5e 100644 --- a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs @@ -91,7 +91,7 @@ namespace Microsoft.Extensions.DependencyInjection }); // Hosting doesn't add IHttpContextAccessor by default - services.TryAddSingleton(); + services.AddHttpContextAccessor(); // Identity services services.TryAddScoped, UserValidator>(); services.TryAddScoped, PasswordValidator>(); diff --git a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/InMemoryStoreWithGenericsTest.cs b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/InMemoryStoreWithGenericsTest.cs index ca16d349d7..48b71e970b 100644 --- a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/InMemoryStoreWithGenericsTest.cs +++ b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/InMemoryStoreWithGenericsTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test public InMemoryEFUserStoreTestWithGenerics() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddDbContext(options => options.UseInMemoryDatabase("Scratch")); _context = services.BuildServiceProvider().GetRequiredService(); } diff --git a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/TestIdentityFactory.cs b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/TestIdentityFactory.cs index c8ba6c922f..565f498251 100644 --- a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/TestIdentityFactory.cs +++ b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/TestIdentityFactory.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test public static IServiceCollection CreateTestServices() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddLogging(); services.AddIdentity(); return services; diff --git a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/DbUtil.cs b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/DbUtil.cs index 4aab1f2072..7d6b79df70 100644 --- a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/DbUtil.cs +++ b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/DbUtil.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test { services = new ServiceCollection(); } - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddDbContext(options => options.UseSqlServer(connectionString)); return services; } diff --git a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/SqlStoreTestBase.cs b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/SqlStoreTestBase.cs index 101ad85e47..39db75d3db 100644 --- a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/SqlStoreTestBase.cs +++ b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/SqlStoreTestBase.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test protected override void SetupIdentityServices(IServiceCollection services, object context) { - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddSingleton((TestDbContext)context); services.AddLogging(); services.AddSingleton>>(new TestLogger>()); diff --git a/test/Microsoft.AspNetCore.Identity.Service.EntityFrameworkCore.Test/Utilities/DbUtil.cs b/test/Microsoft.AspNetCore.Identity.Service.EntityFrameworkCore.Test/Utilities/DbUtil.cs index 4aab1f2072..7d6b79df70 100644 --- a/test/Microsoft.AspNetCore.Identity.Service.EntityFrameworkCore.Test/Utilities/DbUtil.cs +++ b/test/Microsoft.AspNetCore.Identity.Service.EntityFrameworkCore.Test/Utilities/DbUtil.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test { services = new ServiceCollection(); } - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddDbContext(options => options.UseSqlServer(connectionString)); return services; } diff --git a/test/Microsoft.AspNetCore.Identity.Test/IdentityBuilderTest.cs b/test/Microsoft.AspNetCore.Identity.Test/IdentityBuilderTest.cs index 02f602c33b..7fa2de9229 100644 --- a/test/Microsoft.AspNetCore.Identity.Test/IdentityBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Identity.Test/IdentityBuilderTest.cs @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Identity.Test { var services = new ServiceCollection() .AddSingleton(new ConfigurationBuilder().Build()) - .AddSingleton() + .AddHttpContextAccessor() .AddLogging(); services.AddIdentity() .AddUserStore() diff --git a/test/Microsoft.AspNetCore.Identity.Test/UserManagerTest.cs b/test/Microsoft.AspNetCore.Identity.Test/UserManagerTest.cs index 3114713f3b..3f94f56008 100644 --- a/test/Microsoft.AspNetCore.Identity.Test/UserManagerTest.cs +++ b/test/Microsoft.AspNetCore.Identity.Test/UserManagerTest.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Identity.Test .AddSingleton(config) .AddTransient, NoopUserStore>(); services.AddIdentity(); - services.AddSingleton(); + services.AddHttpContextAccessor(); services.AddLogging(); var manager = services.BuildServiceProvider().GetRequiredService>(); Assert.NotNull(manager.PasswordHasher); @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Identity.Test var services = new ServiceCollection() .AddSingleton(config) .AddTransient, NoopUserStore>() - .AddSingleton(); + .AddHttpContextAccessor(); services.AddLogging(); @@ -1544,7 +1544,7 @@ namespace Microsoft.AspNetCore.Identity.Test .AddLogging() .AddSingleton(describer) .AddSingleton>(store.Object) - .AddSingleton(); + .AddHttpContextAccessor(); services.AddIdentity();