<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Unit of Work Pattern</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Unit of Work Pattern</description>
  <pubDate>Sun, 12 Apr 2026 23:31:49 -700</pubDate>
  <lastBuildDate>Mon, 22 Oct 2012 17:22:51 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=3732</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Unit of Work Pattern : By all means vote those two up!Meanwhile,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14940#14940</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 3732<br /><strong>Posted:</strong> 22-Oct-2012 at 5:22pm<br /><br />By all means vote those two up!&nbsp;<div><br></div><div>Meanwhile, I think you have a choice today that is not as terrible as you see it.</div><div><br></div><div><b>Extract the EFContextProvider</b></div><div><br></div><div>First, you can pull the EFContextProvider out of the controller and wrap it in your own UoW component. It would take about two minutes to create "MyUoW", move EFContextProvider inside it, and have your WebApi controller methods delegate to MyUoW in exactly the same way they now call EFContextProvider. Use Web API dependency injection to get it into your controller instances just like John does in CodeCamper (CC).</div><div><br></div><div>This is not <i>substantively </i>different than CC. Of course we're just moving the pea from under one cup to under another.</div><div><br></div><div><b>Dispatch validations by type</b></div><div><br></div><div><b>@jagerm</b>'s concerns are an opportunity to make MyUoW carry its own weight. I wouldn't write a <i>BeforeSaveEntity </i>method for each type. &nbsp;I doubt I would ever use this method. I guess it's OK for a tiny model but not a medium-sized model and it's just wrong architecturally IMO. The UoW shouldn't know details like this for each type.&nbsp;</div><div><br></div><div>Instead, I'd want the UoW act as a dispatcher (or maybe delegate to a dispatcher)* in a <b>BeforeSaveEntities </b>(plural) method (see&nbsp;<a href="http://www.breezejs.com/&#100;ocumentati&#111;n/server-side-intercepti&#111;n" target="_blank">http://www.breezejs.com/documentation/server-side-interception)</a>.</div><div><br></div><div>&nbsp; <i>*the UoW either inherits from EFContextProvider and override BeforeSaveEntities or can delegate to a component that does.</i></div><div><br></div><div>The <b>BeforeSaveEntities&nbsp;</b>method receives a dictionary of types, each entry being a list of entities of that type that are to be saved. For each type it looks for a corresponding "save validation components". These are separate classes that are either registered or discovered during service initialization. Your <i>BeforeSaveEntities </i>dispatches its arguments* to each of these components in turn. You get the idea.</div><div><br></div><div><i>* make sure to pass the entire SaveMap in your protocol; sometimes a save validation component needs to know what else is being saved with it; think about an&nbsp;<b>order&nbsp;</b>and its&nbsp;<b>orderdetails</b>.</i></div><div><br></div><div>The point is that <b>no one class tries to do too much</b>. The <i>Controller </i>stays thin because it talks to the injected <i>MyUoW</i>. The <i>MyUoW </i>stays thin because it dispatches saving chores to <i>type-focused validation components</i> that know what to do with entities of their dedicated type. Turtles all the way down.</div><div><br></div><div>This dispatching is not materially different than what you'd get if you had controllers-per-type. It does put dispatching under your control which, depending on your perspective, is either a good thing or a bad thing (I like it personally).</div><div><br></div><div><b>@jagerm</b>&nbsp;- does this meet your need? If not why not?</div><div><br></div><div>And now ... a rant from me ... to encourage you to vote for a feature dear to my heart.</div><div><br></div><div><b>Why Named Saves?</b></div><div><br></div><div>From my perspective, what is missing from the above serviceable approach .. and it's missing from CodeCamper and every other Web API example I've seen ... is the<i> ability to differentiate save requests semantically</i>.&nbsp;</div><div><br></div><div>For example, per my app's business rules it may be important for me to have a <i>SaveNewOrder </i>command. The only entities to be saved in such a command should be a single new order and the new orderdetails associated with that one order. The save bundle should not contain a new customer or a changed customer or orders for other customers or order details for a different order. If I see any of these entities in the bundle, it's an invalid command that I should reject on sight.</div><div><br></div><div>Then I have an <i>UpdateCustomer </i>command with similar rules governing both the contents of the save bundle and what kinds of changes are allowed.</div><div><br></div><div>We're no longer talking CRUD. We're talking commands with messages. The upside is close attention to the semantics of each save. The downside is close attention to the semantics of each save &nbsp;:) &nbsp; because you signed up to write and maintain a ton of commands! &nbsp; I suspect that developers under real deadlines will take a hybrid approach, writing commands for sensitive entity types and using the "SaveChanges" command for all other types; the "SaveChanges" interceptor would disallow attempts to save Customer, Order, OrderDetails but would allow other harmless types to go through the dispatching logic described above. &nbsp;This is my vision.</div><div><br></div><div>Now you could hack your way to this beautiful world today with a single <i>SaveChanges </i>method and its dispatcher. For example, you could include in the save payload (inside the save bundle) a pseudo-entity called "SaveCommand". The dispatcher detects this <i>SaveCommand </i>entity (which is never actually saved) and redirects to the appropriate save handler based on the value of that command.</div><div><br></div><div>But it's a hack. I want to write clear controller methods. I'd like to be able to decorate them with security attributes. &nbsp;I might want pre- and post-save actions that don't involve persistence (e.g., send a message).&nbsp;</div><div><br></div><div>Most importantly, I want someone reading the controller code to know what is going on! I don't want them to spelunk a dispatching table. If you agree, vote up "Named Save"</div><div><br></div><div>That's the end of my rant on this subject.&nbsp;</div>]]>
   </description>
   <pubDate>Mon, 22 Oct 2012 17:22:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14940#14940</guid>
  </item> 
  <item>
   <title>Unit of Work Pattern : I think two suggestions may help...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14938#14938</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1525" rel="nofollow">pawel</a><br /><strong>Subject:</strong> 3732<br /><strong>Posted:</strong> 22-Oct-2012 at 11:27am<br /><br />I think two suggestions may help - please vote.<div>1. Named Save:&nbsp;<a href="https://breezejs.uservoice.com/forums/173093-breeze-feature-suggesti&#111;ns/suggesti&#111;ns/3140634-named-save" target="_blank">https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions/suggestions/3140634-named-save</a></div><div>2. Save Options:&nbsp;<a href="https://breezejs.uservoice.com/forums/173093-breeze-feature-suggesti&#111;ns/suggesti&#111;ns/3140649-extensible-saveopti&#111;ns-and-queryopti&#111;ns-can-be-int" target="_blank">https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions/suggestions/3140649-extensible-saveoptions-and-queryoptions-can-be-int</a></div><div><br></div>]]>
   </description>
   <pubDate>Mon, 22 Oct 2012 11:27:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14938#14938</guid>
  </item> 
  <item>
   <title>Unit of Work Pattern : I have the exact same question....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14935#14935</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1560" rel="nofollow">jagerm</a><br /><strong>Subject:</strong> 3732<br /><strong>Posted:</strong> 22-Oct-2012 at 8:35am<br /><br />I have the exact same question. &nbsp;I do not feel comfortable exposing my DbContext directly over Web API via OData. &nbsp;I need to know how to add some&nbsp;separation&nbsp;of concerns so I can easily manage row level security. &nbsp;In John Papa's example how would one ensure with Breeze that Session descriptions can only be modified by the Speaker and other row level security without writing every security rule in BeforeSaveEntity; which would end up as an unmanageable mess for larger applications. &nbsp;If we could extend the Unit of Work Pattern somehow this would be ideal. &nbsp;I've been looking at this for a day or so and can't seem to come up with an elegant solution. &nbsp;EFContextProvider attaches records directly to the ObjectContext and calls ObjectContext.SaveChanges(AcceptAllChanges) which seems to imply that Unit of Work won't work...]]>
   </description>
   <pubDate>Mon, 22 Oct 2012 08:35:36 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14935#14935</guid>
  </item> 
  <item>
   <title>Unit of Work Pattern : Hi there,breeze is exactly what...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14930#14930</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1559" rel="nofollow">SirSmackalot</a><br /><strong>Subject:</strong> 3732<br /><strong>Posted:</strong> 22-Oct-2012 at 12:33am<br /><br />Hi there,<br><br>breeze is exactly what i was looking for for my project, nicely done!<br><br>I am quite new to EF, kind of following John Papas course to build my own page. He implemented the Unit of Work-Pattern on the server side. Is there an intelligent way to integrate the EFContextProvider in this pattern or is it obsolete for Breeze?<br><br>Any hint much appreciated :)<br><br><br>]]>
   </description>
   <pubDate>Mon, 22 Oct 2012 00:33:13 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3732&amp;PID=14930#14930</guid>
  </item> 
 </channel>
</rss>