[2.0.1] Allow use of base identity pocos (#1385)
This commit is contained in:
parent
e36e681d54
commit
b865d58786
|
|
@ -96,15 +96,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseType)
|
||||
{
|
||||
var type = currentType.GetTypeInfo();
|
||||
while (type.BaseType != null)
|
||||
var type = currentType;
|
||||
while (type != null)
|
||||
{
|
||||
type = type.BaseType.GetTypeInfo();
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
||||
if (genericType != null && genericType == genericBaseType)
|
||||
{
|
||||
return type;
|
||||
return typeInfo;
|
||||
}
|
||||
type = type.BaseType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
= new ResourceManager("Microsoft.AspNetCore.Identity.EntityFrameworkCore.Resources", typeof(Resources).GetTypeInfo().Assembly);
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>.
|
||||
/// </summary>
|
||||
internal static string NotIdentityRole
|
||||
{
|
||||
|
|
@ -19,13 +19,13 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>.
|
||||
/// </summary>
|
||||
internal static string FormatNotIdentityRole()
|
||||
=> GetString("NotIdentityRole");
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>.
|
||||
/// </summary>
|
||||
internal static string NotIdentityUser
|
||||
{
|
||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>.
|
||||
/// </summary>
|
||||
internal static string FormatNotIdentityUser()
|
||||
=> GetString("NotIdentityUser");
|
||||
|
|
|
|||
|
|
@ -118,11 +118,11 @@
|
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NotIdentityRole" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>.</value>
|
||||
<comment>error when the role does not derive from IdentityRole</comment>
|
||||
</data>
|
||||
<data name="NotIdentityUser" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>.</value>
|
||||
<comment>error when the user does not derive from IdentityUser</comment>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
// 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;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder.Internal;
|
||||
using Microsoft.AspNetCore.Identity.Test;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
protected override void SetupIdentityServices(IServiceCollection services, object context)
|
||||
{
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddSingleton<TestDbContext>((TestDbContext)context);
|
||||
services.AddSingleton((TestDbContext)context);
|
||||
services.AddLogging();
|
||||
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
|
||||
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
|
||||
|
|
|
|||
|
|
@ -59,5 +59,14 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
// This used to throw
|
||||
var builder = services.AddIdentity<GuidUser, GuidRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<Guid>, IdentityRole<Guid>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -37,5 +37,14 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
// This used to throw
|
||||
var builder = services.AddIdentity<IntUser, IntRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<int>, IdentityRole<int>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -39,5 +39,13 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
var builder = services.AddIdentity<StringUser, StringRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<string>, IdentityRole<string>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue