grandchamp / Identity.Dapper

Identity package that uses Dapper instead EntityFramework for use with .NET Core
MIT License
268 stars 62 forks source link

Using GUID instead of int #54

Closed Bojanema closed 6 years ago

Bojanema commented 6 years ago

Hi,

I tried setting up my project to use GUID instead of int on User and Role tables, however, I encounter the following error:

System.TypeLoadException: GenericArguments[0], 'Identity.Dapper.Entities.DapperIdentityUser1[System.Guid]', on 'Identity.Dapper.Stores.DapperUserStore7[TUser,TKey,TUserRole,TRoleClaim,TUserClaim,TUserLogin,TRole]' violates the constraint of type parameter 'TUser'. at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type) at System.RuntimeTypeHandle.Instantiate(Type[] inst) at System.RuntimeType.MakeGenericType(Type[] instantiation)

I followed your instructions by adding the following to Startup.cs

services.AddIdentity<DapperIdentityUser<Guid>, DapperIdentityRole<Guid>>

grandchamp commented 6 years ago

Can't you use string instead?

Bojanema commented 6 years ago

You know, I am sorry, this works as intended. I missed one of your instructions.

services.AddIdentity<DapperIdentityUser<Guid>, DapperIdentityRole<Guid>>()
        .AddDapperIdentityFor<T, Guid>();

I didn't add Guid on the last call. Please close/trash this.

Bojanema commented 6 years ago

@grandchamp Since this is still open, just wanted to ask you a side question. Where do you bind your SignInManager? Is it in Transient or Scoped? I believe there is a bug with this, but can't find this info to confirm.

What happens is I logout in a method and return the page to the user, however, the SignInManager injected in the view still thinks the user is loged in. If I refresh the page then it shows logged out in the view. I really think its something to do with how its bound, Scope vs Transient.

grandchamp commented 6 years ago

I'm using scoped. I'll take a look on how MS Identity registers things. You can take a look on https://github.com/grandchamp/Identity.Dapper/blob/master/src/Identity.Dapper/Extensions/ServiceCollectionExtensions.cs AddStores

grandchamp commented 6 years ago

MS uses scoped too. https://github.com/aspnet/Identity/blob/669aaea3f3d9e55f8edb33679910a49bdebfd9fc/src/Microsoft.AspNetCore.Identity.EntityFrameworkCore/IdentityEntityFrameworkBuilderExtensions.cs#L72