Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I’m quiet new in DDD so don’t hesitate to comment if you disagree, as you I’m here to learn. </p> <p>Personally I don’t understand why you should reference the infrastructure layer from your domain. In my opinion the domain shouldn’t be dependent on the infrastructure. The Domain objects should be completely ignorant on which database they are running on or which type of mail server is used to send mails. By abstracting the domain from the infrastructure it is easier to reuse; because the domain don’t know on which infrastructure its running.</p> <p>What I do in my code is reference the domain layer from my infrastructure layer (but not the opposite). Repositories know the domain objects because their role is to preserve state for the domain. My repositories contains my basic CRUD operations for my root aggregates (get(id), getall(), save(object), delete(object) and are called from within my controllers. </p> <p>What I did on my last project (my approach isn’t purely DDD but it worked pretty well) is that I abstracted my Repositories with interfaces. The root aggregates had to be instantiated by passing a concrete type of a Repository: </p> <p>The root aggregate had to be instantiated through a repository by using the Get(ID) or a Create() method of the repository. The concrete Repository constructing the object passed itself so that the aggregate could preserve his state and the state of his child objects but without knowing anything of the concrete implementation of the repository. e.g.:</p> <pre><code>public class PostRepository:IPostRepository { ... public Post Create() { Post post=new Post(this); dbContext.PostTable.Insert(post); return post; } public Save(post) { Post exitingPost=GetPost(post.ID); existingPost = post; dbContext.SubmitChanges(); } } public class Post { private IPostRepository _repository internal Post(IPostRepository repository) { _repository = repository; } ... Public Save() { _repository.Save(this); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload