How to handle many-to-many relationships with ASP.NET Core Identity in a Clean Architecture project?

146 Views Asked by At

I'm working on a project that follows the Clean Architecture pattern, and I'm using ASP.NET Core Identity to handle authentication and authorization. I have a User entity that inherits from IdentityUser, and I need to establish many-to-many relationships with other entities in the domain.

The problem is that I can't add a dependency on Microsoft.AspNetCore.Identity.EntityFrameworkCore to the domain layer, as it would violate the dependency rule. Therefore, I decided to move the User class to the infrastructure layer, where I can have a reference to Microsoft.AspNetCore.Identity.EntityFrameworkCore. However, this created a new issue, as I can't use navigation properties to configure the relationships with other entities from the domain layer.

What's the best approach to handle this situation? Should I move the User class back to the domain layer, even if it means violating the dependency rule? Or is there a way to configure many-to-many relationships without navigation properties, while keeping the User class in the infrastructure layer?

I'd appreciate any guidance on this topic. Thank you!

I want to use navigation properties freely. But I don't I want to violate essential rules.

0

There are 0 best solutions below