Search code examples
c#asp.net-coreasp.net-identityasp.net-identity-2

Extending IdentityUser in Asp.Net Core Identity 2.0 when it's a NuGet package


In this blog ASP.NET Core 2.1.0-preview1: Introducing Identity UI as a library I found that the concept of identity in ASP.Net Core 2.0 is being shipped as a NuGet package.

I'm working on a project where I need to extend the included IdentityUser to be in multiple one to many relationships.

I would like to add properties onto my user class like List and List.

With IdentityUser in a NuGet package how do people customize it? Does everyone opt out of the NuGet package if they want to customize it?


Solution

  • that blog is specifically talking about UI elements, whereas you seem to be asking about back-end code...

    If you just want to add some custom stuff to the User model, this is already supported: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-2.2

    Basically you can create a custom class which derives (inherits from) IdentityUser, add custom properties to this, then when setting up Identity you can use this rather than the stock IdentityUser.