<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>TJ Solutions - Request Response Service Layer</title>
    <link>http://www.tjsolutions.nl/</link>
    <description />
    <language>en-us</language>
    <copyright>Tijmen van de Kamp, Tom de Koning</copyright>
    <lastBuildDate>Mon, 16 Nov 2009 18:01:36 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>blog@tjsolutions.nl</managingEditor>
    <webMaster>blog@tjsolutions.nl</webMaster>
    <item>
      <trackback:ping>http://www.tjsolutions.nl/Trackback.aspx?guid=b9a7be28-2e24-451c-82a2-4ac11d6922d4</trackback:ping>
      <pingback:server>http://www.tjsolutions.nl/pingback.aspx</pingback:server>
      <pingback:target>http://www.tjsolutions.nl/PermaLink,guid,b9a7be28-2e24-451c-82a2-4ac11d6922d4.aspx</pingback:target>
      <dc:creator>Tom</dc:creator>
      <wfw:comment>http://www.tjsolutions.nl/CommentView,guid,b9a7be28-2e24-451c-82a2-4ac11d6922d4.aspx</wfw:comment>
      <wfw:commentRss>http://www.tjsolutions.nl/SyndicationService.asmx/GetEntryCommentsRss?guid=b9a7be28-2e24-451c-82a2-4ac11d6922d4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just a quick update on my <a href="http://www.tjsolutions.nl/2009/10/31/FunctionalProgrammingWithTheRequestResponseServiceLayer.aspx">previous</a> posting
following one of the comments made by <a href="http://benpittoors.wordpress.com/">den
Ben</a></p>
        <p>
 
</p>
        <p>
just out of curiosity... why wouldn't you 
<br />
dispatcher.Add&lt;SaveDocumentRequest&gt;(s =&gt; 
<br />
{ 
<br />
s.Document = document; 
<br />
s.UserID = userID; 
<br />
});
</p>
        <p>
 
</p>
        <p>
He's absolutely right. Using a Func forced me to (mis)use the params keyword as you
are not allowed  to use the above syntax with the old code: 
</p>
        <pre class="code">
          <span style="color: blue">public virtual </span>
          <span style="color: #2b91af">IDispatcher </span>Add&lt;TRequestType&gt;(<span style="color: blue">params </span><span style="color: #2b91af">Func</span>&lt;TRequestType, <span style="color: blue">object</span>&gt;[]
funcs) <span style="color: blue">where </span>TRequestType : <span style="color: #2b91af">Request</span>, <span style="color: blue">new</span>()
{ TRequestType request = <span style="color: blue">new </span>TRequestType(); <span style="color: blue">foreach </span>(<span style="color: blue">var </span>func <span style="color: blue">in </span>funcs)
{ func.Invoke(request); } AddRequest(request, <span style="color: blue">false</span>); <span style="color: blue">return
this</span>; }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>
        </p>
        <p>
I actually had noticed the code not using the return value by the func but disregarded
it as I was a bit too happy with the "elegance" of my inital solution.
</p>
        <p>
But I think (and I think you'll agree) that using an Action is much cleaner here:
</p>
        <pre class="code">
          <span style="color: blue">public virtual </span>
          <span style="color: #2b91af">IDispatcher </span>Add&lt;TRequestType&gt;(<span style="color: #2b91af">Action</span>&lt;TRequestType&gt;
action) <span style="color: blue">where </span>TRequestType : <span style="color: #2b91af">Request</span>, <span style="color: blue">new</span>()
{ TRequestType request = <span style="color: blue">new </span>TRequestType(); action(request);
AddRequest(request, <span style="color: blue">false</span>); <span style="color: blue">return
this</span>; }</pre>
        <p>
 
</p>
        <p>
Thanks <a href="http://benpittoors.wordpress.com/">den Ben</a>!<a href="http://11011.net/software/vspaste"></a></p>
        <img width="0" height="0" src="http://www.tjsolutions.nl/aggbug.ashx?id=b9a7be28-2e24-451c-82a2-4ac11d6922d4" />
      </body>
      <title>Functional programming with the Request/Response Service Layer part2</title>
      <guid isPermaLink="false">http://www.tjsolutions.nl/PermaLink,guid,b9a7be28-2e24-451c-82a2-4ac11d6922d4.aspx</guid>
      <link>http://www.tjsolutions.nl/2009/11/16/FunctionalProgrammingWithTheRequestResponseServiceLayerPart2.aspx</link>
      <pubDate>Mon, 16 Nov 2009 18:01:36 GMT</pubDate>
      <description>&lt;p&gt;
Just a quick update on my &lt;a href="http://www.tjsolutions.nl/2009/10/31/FunctionalProgrammingWithTheRequestResponseServiceLayer.aspx"&gt;previous&lt;/a&gt; posting
following one of the comments made by &lt;a href="http://benpittoors.wordpress.com/"&gt;den
Ben&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
just out of curiosity... why wouldn't you 
&lt;br /&gt;
dispatcher.Add&amp;lt;SaveDocumentRequest&amp;gt;(s =&amp;gt; 
&lt;br /&gt;
{ 
&lt;br /&gt;
s.Document = document; 
&lt;br /&gt;
s.UserID = userID; 
&lt;br /&gt;
});
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
He's absolutely right. Using a Func forced me to (mis)use the params keyword as you
are not allowed&amp;#160; to use the above syntax with the old code: 
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public virtual &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDispatcher &lt;/span&gt;Add&amp;lt;TRequestType&amp;gt;(&lt;span style="color: blue"&gt;params &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TRequestType, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;[]
funcs) &lt;span style="color: blue"&gt;where &lt;/span&gt;TRequestType : &lt;span style="color: #2b91af"&gt;Request&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt;()
{ TRequestType request = &lt;span style="color: blue"&gt;new &lt;/span&gt;TRequestType(); &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;func &lt;span style="color: blue"&gt;in &lt;/span&gt;funcs)
{ func.Invoke(request); } AddRequest(request, &lt;span style="color: blue"&gt;false&lt;/span&gt;); &lt;span style="color: blue"&gt;return
this&lt;/span&gt;; }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I actually had noticed the code not using the return value by the func but disregarded
it as I was a bit too happy with the "elegance" of my inital solution.
&lt;/p&gt;
&lt;p&gt;
But I think (and I think you'll agree) that using an Action is much cleaner here:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public virtual &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDispatcher &lt;/span&gt;Add&amp;lt;TRequestType&amp;gt;(&lt;span style="color: #2b91af"&gt;Action&lt;/span&gt;&amp;lt;TRequestType&amp;gt;
action) &lt;span style="color: blue"&gt;where &lt;/span&gt;TRequestType : &lt;span style="color: #2b91af"&gt;Request&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt;()
{ TRequestType request = &lt;span style="color: blue"&gt;new &lt;/span&gt;TRequestType(); action(request);
AddRequest(request, &lt;span style="color: blue"&gt;false&lt;/span&gt;); &lt;span style="color: blue"&gt;return
this&lt;/span&gt;; }&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Thanks &lt;a href="http://benpittoors.wordpress.com/"&gt;den Ben&lt;/a&gt;!&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tjsolutions.nl/aggbug.ashx?id=b9a7be28-2e24-451c-82a2-4ac11d6922d4" /&gt;</description>
      <comments>http://www.tjsolutions.nl/CommentView,guid,b9a7be28-2e24-451c-82a2-4ac11d6922d4.aspx</comments>
      <category>.NET</category>
      <category>Functional</category>
      <category>Linq</category>
      <category>Request Response Service Layer</category>
    </item>
  </channel>
</rss>