✅ [DDD] Reference IdentityUser in Domain model class
Hi, I'm starting my jurney with DDD so please take it easy on me 😄
Any pointers on how to reference AppUser : IdentityUser (that's in Persistence layer) in a domain model class?
I have some entities that have:
and I want to use .Include(u => u.Owner) when getting the data using EF Core.
Problem is that AppUser : IdentityUser is defined in the Persistence layer, which Domain Layer has no access to, nor does it have the EF package.
What would be the best approach to deal with this?
5 Replies
either you move AppUser in domain or you create a surrogate class for AppUser in domain that will be mapped to AppUser
or, vertical-slice-speaking, you put a domain layer in the persistence layer so that you can create a module that will be used by module that has that class with OwnerId and Owner
I tried making a User surrogate class but on DB creation a separate "User" table is created instead of using the default IdentityUser table.
I also tried using a IUser interface in the Domain:
and then in the Persistance:
but EF does not let this go because:
am I missing something here?
types in ef can't be interfaces, they have to be concrete
also you should look at your configuration, for example if you are using table per hierarchy or what have you
I was able to make it work by casting the interface:
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.