Sustainability design

For a project, we begin to look at the save functions and how we want to implement this. We are currently looking at preserving clean architecture, possibly for onion architecture. Thus, we want to define a new outer layer in which the save layer is located.

We look at various ORM solutions (we seem to converge to the Entity Framework) using SQLite as a data store, and we are faced with the problem: how to manage the identifier and deal with adding / removing to a collection or moving some instance between various collections.

At the heart of our bow, we want to keep our POCO objects. Thus, we do not want any identifier property to be added to our business objects. Only inside the persistence layer do we want to have classes with object identifiers. Due to this separation:

  • How to remove a business object from a collection to remove a row from a SQLite database?
  • More complex (at least I think so), how did an instance of POCO move from one collection to another to change the SQLata databaserow foreign key? (Instead of deleting a row and recreating it with the same values)

Looking around the Internet, I have not yet found an implementation somewhere that demonstrates the level of conservation in the design of a clean architecture. Many high-level diagrams and "depend only on the internal", but there are no examples of source code for demonstration. Some possible solutions that we have come up with so far:

  • Try searching between POCO instances and their representative "database model objects" (which have an identifier, etc.) within the retention level. When the project state is saved, the business model objects will be mapped to the database model objects and accordingly update the state for matches. Then the object is saved.
  • persistence -, -, persistence, . POCO , , .

1 - . 2 , , , , " ".

? 2 , ? - ( iOs https://github.com/luisobo/clean-architecture, , ).

+4
2

-, . . . EAN ( ). ids ( , , , ).

.

- (, ), . , . . , . ? , -.

, , . , :

public class ForumPost
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
    public User Creator { get; set; }
}

public class User
{
    public string Id { get; set; }
    public string FirstName { get; set; }
}

:

post.User.FirstName = "Arnold"; 
postRepos.Update(post);

? - , ?

ORM . .

. - . .

public class ForumPost
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
    public int CreatorId { get; set; }
}

, :

  • , , .

  • .

0

, , . .

( , , ..) , .

, , - - Object/Entity.

  • Value , , .
  • . - .

, , . , , (, ).

, " DDD" ( " " 5 "" ).


. DDD - . , DDD ID. DDD - .

+2

Source: https://habr.com/ru/post/1619462/


All Articles