I write BFF (Backend For Frontend) and it's domain is to provide user info and microservices integration.
The User domain model looks like below:
public class User
{
public required Guid Id { get; set; }
public required string Name { get; set; }
public required AvatarUrl AvatarUrl { get; set; }
}
The domain have to know user information. But the application layer needs to know also from which identity provider user comes. To store that information, my User entity in Infrastructure layer looks like it:
internal class User
{
public Guid Id { get; set; }
public string ExternalId { get; set; }
public ExternalIdentityProvider ExternalIdentityProvider { get; set; }
public bool UseExternalProviderProfile { get; set; }
public string Name { get; set; }
public string AvatarUrl { get; set; }
}
So I wanted to write some handler in Application layer to retrieve user information, and here problem occurs because the Domain model has not enough information. The domain model doesnt tell me whether shall I call identity provider or just use information stored locally.
So I need to "extend" the Domain model in Application layer, so I can get necessary information about User. But here next problem occurs because my Repository won't return the User Domain model. It will return the extended user model.
The current User domain model is enough for most logic, the case where it isn't is some sort of of "special case", but this special case is an entry point to rest of logic.
What to do in this case? The simplest way would be to just extend the existing Domain model instead of creating extended model in Application layer. But the Domain doesn't need to know all these things which are needed by Application layer. What to do?
User domain modelis used to representUserwhich will flow over whole application. But it stores too few data and simultaneously enough for domain. It's because the domain is interested in user only, it doesn't need to know from which identity provider it comes while application layer at some points needs to know from where user comes. 2. I have never heard about clean architecture versions and when I google it I can see nothing appropriateUser domain modelis enough for most logic, the case where it isn't is some sort of of "special case", but this special case is an entry point to rest of logic.