fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.

Home Page:https://fullstackhero.net/dotnet-webapi-boilerplate/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Model relationship with ApplicationUser

nageshkinge opened this issue · comments

commented

Could you please help me create a Order class which belongs to User?

I tried as below but the ApplicationUser is part of Infrastructure project which should not be imported in Domain Project as per architecture.

`
public class Order : AuditableEntity, IAggregateRoot
{
....
public Guid UserId{ get; set; }

public virtual ApplicationUser User { get; set; }
}
`
I am missing something or doing it wrong way?

Using DDD principles you shouldn't link Aggregate Roots. The Order and ApplicationUser are aggregate roots.

As a rule of thumb an Aggregate should only reference other aggregates by their Id. That means you shouldn't add navigation properties to other aggregates (this prevents different aggregates manipulating each other and leaking business logic to each other).

You should explicitly query the ApplicationUser by the UserId if you need to get User information

If you have OrderLine class then this would be an entity class and you could therefore attached to the Order class i.e.

public class Order : AuditableEntity, IAggregateRoot
{
....
  public Guid UserId{ get; set; }

  public Collection<OrderLine> OrderLines {get; set;}
}

Hope that helps :-)
Kevin