Domain vrstva: Nemá závislosti na žiadnej inej vrstve.
Aplikačná vrstva: Referencuje Domain vrstvu a koordinuje logiku.
Prezentačná vrstva: Referencuje Aplikačnú vrstvu.
Infra vrstva: Referencuje Aplikačnú a prípadne Domain vrstvu.
5. Príklad použitia DTO a ViewModel v Blazor Server App
Domain (Entity):
public class Customer
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Application (DTO):
public class CustomerDto
{
public Guid Id { get; set; }
public string FullName { get; set; }
public string ContactEmail { get; set; }
}
Blazor App (ViewModel):
public class CustomerViewModel
{
public string FullName { get; set; }
public string ContactEmail { get; set; }
public string DisplayName => $"{FullName} ({ContactEmail})";
}
Mapovanie v Aplikačnej vrstve:
public class CustomerService
{
public CustomerDto MapToDto(Customer customer)
{
return new CustomerDto
{
Id = customer.Id,
FullName = customer.Name,
ContactEmail = customer.Email
};
}
}