'CleanArchitecture: where to put View-related data that can be stored via EF?

My question is simple but somehow complex in detail! I try to explain it ...

I built my application in a 'Clean Architecture' manner, where i have Entities (not to be confused with database entities) at most top layer. They just represent domain specific data (so basically getters/setters + little validation logic + business rules). The layer beneath is called 'Application' where i process all incoming requests, sometimes from APIs, sometimes from web applications and so on. those requests can lead to CRUD - operations directed to a database (not a must). For this i invented a third layer named Infrastructure, where i use EF to map from the Entities (in the Entities - Layer) to database entities. So far its fine ...

Now i have an web application that requires to display some visual elements on a canvas (for example). These visual elements should be able to show some descriptive text and represent the states from an specific Entity out of the Entities - Layer. I have written ViewModels/DTOs that simply map to that Entity for responding to incoming requests and to preserve loose coupling. Now there is the requirement that i have to make these visual elements adjustable on screen (via mouse + drag and drop) and to persist those adjustment (with coordinates).

Now my simple question is: Where should those coordinates reside? Putting them into the Entity in the Entities - layer is wrong in my opinion, because there should never be any state corresponding to the visuals of a View.

I need to store those coordinates via EF, so i need to have a model to map from and i used my Entities for that.

The configuration looks like:

public class SpotConfiguration : IEntityTypeConfiguration<Spot>
{
    public void Configure(EntityTypeBuilder<Spot> builder)
    {
        if (builder == null) 
            throw new ArgumentNullException(nameof(builder));                    

        builder.HasOne(x => x.Area)
            .WithMany(x => x.Spots)
            .HasForeignKey(x => x.AreaId);

        builder.Property(x => x.Description)
            .IsRequired()
            .HasMaxLength(10);      
    }
}

The Spot is the Entity which needs to refer to the coordinates. There coordinates are only required for one web application, but the Entity is used in other Domains aswell!

I hope you understand my question! :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source