Referencing ApplicationUser in the Infrastructure library from an entity in the ApplicationCore library using Clean Architecture

asp.net-core asp.net-core-mvc c# clean-architecture entity-framework-core

Question

I am following the Microsoft Architecture Guide for creating an ASP.NET Core Web Application.

The guide implements the clean architecture pattern which is pretty straight forward.

If you look at the sample project which is using the clean architecture pattern you will see that there is an Infrastructure/Identity folder that contains the ApplicationUser.cs class.

My issue:
I am using Entity Framework and one of my Business Entities in the ApplicationCore class library needs to contain a list of ApplicationUser. The ApplicationCore library shouldn't be referencing any other projects. It contains all of the Interfaces and Business Entities. How can I keep the ApplicationUser class in my Infrastructure/Identity project and still use it in one of my business entities in the ApplicationCore project without breaking the rules.

I know one solution is to not store the ApplicationUser entity in my Infrastructure project. However, I feel like it should be there since it will always rely on Identity as it implements IdentityUser.

1
1
12/7/2018 5:16:37 AM

Accepted Answer

In Clean Architecture:

Application Core Types

• Entities (business model classes that are persisted) and Aggregates

• Interfaces

• Services

• DTOs

• Specifications

• Exceptions

Infrastructure Types

• EF Core types (DbContext, Migrations)

• Data access implementation types (Repositories)

• Infrastructure-specific services (FileLogger, SmtpNotifier, etc.)

So the ApplicationUser.cs is an entity, it shouls be in Application Core

4
12/7/2018 6:07:01 AM

Popular Answer

User is an entity and it should be in Core layer.

But you shouldn't use ApplicationUser : IdentityUser in the Core layer because it's tied up to the ASP.NET Identity. The Core layer should not know what technologies are going to implement the domain.

What if tomorrow you want to use another library for user management? That's not the Core layer's concern.

What you can do is to use an interface or base User class in the Core layer and let the Infrastructure layer be worried about the library choice decision.



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