question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey>

See original GitHub issue

Describe the bug

At the moment, ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey>. This means it is impossible to use Identity Server on application with ApplicationUser : IdentityUser<Guid> (or anything different from IdentityUser<string>)

To Reproduce

Steps to reproduce the behavior:

  1. Using ASP.NET Core 3.0 Preview 4
  2. Create a new React or Angular template with Identity
  3. Change ApplicationUser to extends IdentityUser<Guid> instead of IdentityUser
  4. Get error: Error CS0311 The type 'WebApplication.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'ApiAuthorizationDbContext<TUser>'. There is no implicit reference conversion from 'WebApplication.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'.

Expected behavior

I would expect ApiAuthorizationDbContext to accept another generic to indicate the key type (e.g. ApiAuthorizationDbContext<ApplicationUser, Guid>)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

18reactions
cherchykcommented, Jan 4, 2020

2020 Looks like it was not fixed yet…

Am I wrong?

5reactions
ajcvickerscommented, May 2, 2019

Re-opening, since ApiAuthorizationDbContext doesn’t follow best practices for a DbContext shipped for others to use. In particular:

  • It should expose a public constructor that takes a generic DbContextOptions<TContext>. Otherwise people resolving this directly will have issues when multiple contexts are registered in D.I.
  • It should expose a protected constructor that takes a non-generic DbContextOptions for use when other classes inherit from it.
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is different between ApiAuthorizationDbContext and ...
... ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey> . This means it is impossible to use ...
Read more >
ASP .NET Core Identity custom ApiAuthorizationDbContext
Currently, you need to custom ApiAuthorizationDbContext , this issue has been tracked through ApiAuthorizationDbContext force TUser to extends IdentityUser ...
Read more >
Identity model customization in ASP.NET Core
This article describes how to customize the underlying Entity Framework Core data model for ASP.NET Core Identity.
Read more >
ApiAuthorizationDbContext<TUser> Class
Gets or sets the DbSet<TEntity> of role claims. (Inherited from IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken>).
Read more >
Custom User Management in ASP.NET Core MVC ...
This is where you will need to extend the IdentityUser class with your own properties. In the Models folder, create a new class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found