Note that there are some explanatory texts on larger screens.

plurals
  1. POBest design for domain service
    text
    copied!<p>I have a question on what's the best design for my domain service. The use case is to create some entities based on user selected conditions.</p> <p>The workflow of the app that will use this service:</p> <ol> <li>User selects some conditions (like date, and other data)</li> <li>He gets a list of "propositions" of the entities. He can select all of them, or only some.</li> <li>The entities are created</li> </ol> <p>What would be the best design for the domain service? I have two in mind:</p> <h2>Solution 1</h2> <pre><code>interface IMyDomainService { IEnumerable&lt;EntityProposition&gt; GetEntitiesPropositions(Conditions conditions); void CreateEntities(Conditions conditions); } </code></pre> <p>In this case i would probably have some private method on the service that will be used by both of those. <em>EntityProposition</em> class is basicly 1:1 of what will be displayed in the view. There is some data in that class that is not part of the entity itself.</p> <h2>Solution 2</h2> <pre><code>interface IMyDomainService { IEnumerable&lt;EntitiyData&gt; GetDataForEntities(Conditions conditions); void CreateEntities(IEnumerable&lt;EntityData&gt; entities); } </code></pre> <p>What would be the private method in Solution 1 is now exposed in interface. <em>EnityData</em> class holds all data for the entity that is relevant for creating the entity itself and displaying all the data for view.</p> <p>To add some context: This service is now used directly by ASP.NET MVC controller. It seems to me, that if i go with solution#2 i will have to create some additional application service, so it will wrap the logic of geting the data and creating entities.</p> <h2>EDIT 1</h2> <p>I will ask the question from different perspective: Should my controller look like this:</p> <pre><code>public ActionResult GetPropositions(Condtidions condtitions) { var entitiyData= service.GetEntityData(conditions); return Json(entitiyData.ToViewModel()); } public void CreateEntities(Conditions conditions) { var entitiyData= service.GetEntityData(conditions); service.CreateEntities(entitiyData); } </code></pre> <p>or:</p> <pre><code>public ActionResult GetPropositions(Condtidions condtitions) { var propositions = service.GetPropositons(conditions); return Json(propositions.ToViewModel()); } public void CreateEntities(Conditions conditions) { service.CreateEntities(conditions); } </code></pre> <p>Of course this is simplified example, just to show my point.</p> <h2>Edit 2</h2> <p>Just as a followup: Firstly I gone with the Solution #2, but later my requirements changed, and i had to go back to the Solution #1. The reason behind was that after generating propositions, user could select few of them, but withing the same scope (conditions).</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