ASPNETUSER as a child to another table

145 views Asked by At

I would like to know if someone can assist me with this little dilemma...

I am following a clean architecture project setup using .net core 3.1. With projects:

  • API
  • Domain
  • Infrastructure
  • Application

In Domain I do not reference any projects (or package) everything else references from it.

And I have the table below in Domain:

Company Table

I have added my identity to the Infrastructure later in which I have have a ApplicationUser which extends IdentityUser.

So the scenario is as follows:

  • user signs up and later gets attached to a company. A company can have many users (this being AspNetUser)
  • So when a user signs in he is attached to that company and can do certain actions under that company
  • And when I retrieve the company it will have a list of users thats attached to it.

So the question I have is, what do I do so that I can have a Company with a collection of users, also without having to add a reference From Domain to infrastructure

1

There are 1 answers

0
plainionist On

Common pattern to resolve this issue is to define an abstraction of your user class or an interface in the domain layer. This abstraction is used in the company class and the user implementation in infrastructure project derives from it.

If inheritance is not an option you can go for an interface in domain project and have an adapter in infrastructure project wrapping the actual user implementation providing access to its properties.