Separation of ASP.NET Core Identity ApplicationUser with relationship to Domain Model Entity

asp.net-core asp.net-identity c# entity-framework-core onion-architecture

Question

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.

1
1
12/29/2019 11:40:25 AM

Popular Answer

How about domain models as interfaces?

So u have some IMember in Domain project (and other types...) and in DAL layer you got DataAccessDbContext with set of Member : IMember (and all other types, ie. Blog : IBlog etc.).

And create separate project for Identity, with IdentityDbContext where MemberIdentiy : IdentityUser, IMember.

Moreover,

as your Domain has IMemberRepository, ISomeEntityRepository etc, and ISomeEntity has IMember prop, you can separately implement SomeEntityRepository in DAL and MemberRepository in Identity project.

You can decide if both context use same database or not.

0
1/19/2020 6:45:45 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow