I'm trying to achieve good separation and architecture between ASP.NET Core Identity and entities in my domain model.
I'm using an Onion architecture in a web application built with ASP.NET Core.
In the core project, Domain
, I have domain models, and one of them being a Member
entity.
Then in another project, Infrastructure
, I have the built in ASP.NET Core Identity setup which contains an ApplicationUser
class that inherits from IdentityUser
.
public class ApplicationUser : IdentityUser
{
}
The idea of having the identity user and member entity separated is good. However, I want to relate them but using Entity Framework Core this seems to be a challenge. I cannot get around this without adding navigation properties in my domain models, which I'd like to avoid.
I was hoping I could do it entirely using Fluent API without having to add properties but that does not seem to be the case.
Any recommendations on how to approach this? Considering the above how could I create a relationship between the identity user and a domain entity without adding dependencies from the core project?
My question is somewhat a duplicate or related to some of these posts here e.g.
and some other posts as well. However, the answers to these questions seems to be workarounds. Maybe that is the only way?
I'm using ASP.NET Core 3.1 and Entity Framework 3.1. for this project.
I Had same business need, I need to separate Identity from other domain models, I decided to follow the following pattern:
1- when create/register new user, we will add identity data in identity table
2- we will add other business data in our domain models lets say Teachers/Students Tables
3- now we need to build the relation between both we can do that by add claims to user in 'UsersClaims' identity table, which by default have the following properties (UserId, ClaimType, ClaimValue) so we will add the our domain model id with identity id
by doing that we have build a virtual relation between Identity-domain
this is a way, you can do this in other side in domains model build mapping table hold same data (identityUserId & domainsUserId)
you can then separate them in different databases if you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With