Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>So my first question is should I use a factory to create this aggregate or is it up to the repository?</p> </blockquote> <p>A factory is responsible for creation while a repository is responsible for persistence. Upon reconstitution, the repository will effectively create instances. However, often times this creation process is done with reflection and doesn't go through a factory to prevent initialization that should only occur at creation time.</p> <blockquote> <p>At this time I have 2 repositories, one for Folder and another for File, but it seems to me I should merge them together.</p> </blockquote> <p>In DDD, you'd have a repository for each aggregate. This repository would be responsible for persisting all entities and value objects that are part of the aggregate. </p> <blockquote> <p>I have my doubts about the location of the service. Should it be moved to the domain layer?</p> </blockquote> <p>IMO, an application service can be placed into the domain layer since it already serves as a facade and keeping them together would bring the benefits of cohesion. One thought about the <code>IoService</code> is that methods such as <code>AddFile</code> would usually be parameterized by aggregate identities as opposed to instances. Since the application service already references a repository, it can load the appropriate aggregates as needed. Otherwise, calling code would be responsible for calling the repository.</p> <blockquote> <p>Should I use the service for creating the folder object. Or should the service just use a factory, which have the responsibility of creating the object and send the created object to the repository?</p> </blockquote> <p>The <code>IoService</code> looks good as is except for the previous comment about being parameterized by identities rather than instances.</p> <blockquote> <p>What about dependency injection in the service, should I inject my services from the UI layer with IOC containers like Unity or should I just hardcode the dependencies in the service?</p> </blockquote> <p>This is a matter of preference. If you can benefit from using an IoC container then use it. However, don't use it just to use it. You are already doing dependency injection, just without a fancy IoC container.</p> <p><strong>SAMPLE</strong></p> <pre><code>class File { public File(string name, Folder folder, FileData data, UserReference createdBy, IEnumerable&lt;string&gt; keywords = null) { //... } } ... class Folder { public File AddFile(string name, FileData data, UserReference createdBy, IEnumerable&lt;string&gt; keywords = null) { var file = new File(name, this, data, createdBy, keywords) this.Files.Add(file); this.Updated = DateTime.UtcNow; return file; } } ... public void AddFile(UserReference userReference, Guid folderId, FileData data, string name, string title = "", IEnumerable&lt;string&gt; keywords = null, bool shared = false) { var folder = _folderRepository.Find(folderId); if (folder == null) throw new Exception(); folder.AddFile(name, data, keywords); _folderRepository.InsertOrUpdate(folder); _folderRepository.UnitOfWork.Save(); } </code></pre> <p>In this example, more of the behavior is delegated to the Folder aggregate and File entity. The application service simple calls the appropriate methods on the aggregate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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