Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a proper use of DTO?
    text
    copied!<p>I'm writing a console application that does a good amount of data retrieval from stored procedure recordsets. For each recordset type I'm working with, I have a Repository that uses EF with custom complex types to retrieve the data:</p> <pre><code>public interface IBalanceSheetRepository { IEnumerable&lt;BalanceSheetRecordDTO&gt; GetBalanceSheetRecords(); } public class BalanceSheetRepository : IBalanceSheetRepository { DBContext _context; ... public IEnumerable&lt;BalanceSheetRecordDTO&gt; GetBalanceSheetRecords() { ObjectResult&lt;BalanceSheetRecord&gt; results = _context.GetBalanceSheet(); return results.Select(CreateBalanceSheetDTOFromDAO); } private static BalanceSheetRecordDTO CreateBalanceSheetDTOFromDAO(BalanceSheetRecord dao) { return new BalanceSheetRecordDTO { ... }; } } </code></pre> <p>Here, <code>BalanceSheetRecord</code> is a complex data type that I created in the designer. I created a DTO to avoid coupling since the BLL should not know about the <code>BalanceSheetRecord</code> type.</p> <p>Here's my question: Since the DTO type is used in the method signature of the repository interface, and since my BLL will ultimately use the repository &amp; be returned a collection of the DTOs, it seems to be a cross-cutting concern. Therefore I have the DTO living in a separate "Infrastructure" assembly, along with the repo interfaces. Is this good practice for what I'm trying to achieve, or did I take a wrong turn somewhere?</p> <p>Also: Is it bad practice to new up the data context in my repository? Is some amount of coupling OK when both components belong to the DAL? I want to use DI but it seems more useful for swapping out the DBContext implementation of the repo for a <code>TestBalanceSheetRepository</code>, for instance.</p>
 

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