Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From my understanding of CQRS you would create a set a DTOs that fulfil the requirements of the user interface screens or applications that may need to consume them. </p> <p>Where this exists in the project is based on the requirements as it would depend if you were going to expose these DTOs via web services. In which case I wouldn't put it in the Web Layer but rather in the Application layer or a dedicated Façade layer. </p> <p>Then you would have a read only repository or data access layer which populates the DTOs directly. I think that the Query side of things should be optimized for read performance in which case direct queries/stored procedures on database views or tables and SqlDataReaders would do the best job here. But it would definitely be worth abstracting this access behind an interface so you can add a cached implementation later down the track. </p> <p>If you're using an ORM and want to map from your Domain Entities to the DTOs then you could have a generic QueryRepository which has methods which take an ISpecification or similar construct for defining your queries then a DtoAssembler object for creating the Dtos from your Domain objects. Then have an implementation has a first class object for each of the queries you are going to perform.</p> <p>Here's a fairly contrived example but I hope it gives you an idea. </p> <pre><code> public interface ISpecification&lt;T&gt; { Expression&lt;Func&lt;T, bool&gt;&gt; Predicate { get; } } public class ActiveCustomersSpecification : ISpecification&lt;Customer&gt; { private Expression&lt;Func&lt;Customer, bool&gt;&gt; predicate; public ActiveCustomersSpecification() { predicate = c =&gt; c.IsActive; } #region ISpecicfication&lt;Customer&gt; Members public Expression&lt;Func&lt;Customer, bool&gt;&gt; Predicate { get { return predicate; } } #endregion } public interface IQueryRepository&lt;T&gt; { IQueryable&lt;T&gt; GetQuery(ISpecification&lt;T&gt; specification); IEnumerable&lt;T&gt; FindAllBy(ISpecification&lt;T&gt; specification); } public class CustomerDtoAssembler { public CustomerDto AssembleFrom(Customer customer) { var customerDto = new CustomerDto { Id = customer.Id }; return customerDto; } } </code></pre>
    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. 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.
    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