<?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 - Linq</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>
    <item>
      <trackback:ping>http://www.tjsolutions.nl/Trackback.aspx?guid=da163853-8db7-45bf-a157-9c0058030aa3</trackback:ping>
      <pingback:server>http://www.tjsolutions.nl/pingback.aspx</pingback:server>
      <pingback:target>http://www.tjsolutions.nl/PermaLink,guid,da163853-8db7-45bf-a157-9c0058030aa3.aspx</pingback:target>
      <dc:creator>Tom</dc:creator>
      <wfw:comment>http://www.tjsolutions.nl/CommentView,guid,da163853-8db7-45bf-a157-9c0058030aa3.aspx</wfw:comment>
      <wfw:commentRss>http://www.tjsolutions.nl/SyndicationService.asmx/GetEntryCommentsRss?guid=da163853-8db7-45bf-a157-9c0058030aa3</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
At my current project we are using a dispatcher class to batch requests to our WCF
layer based on the <a href="http://davybrion.com/blog/2009/11/requestresponse-service-layer-series/">Request/Response
Service Layer</a> created by Davy Brion. Once you call the Get&lt;TResponseType&gt;()
on the dispatcher the WCF layer starts working on the requests one by one and return
them in one roundtrip.
</p>
        <p>
Adding requests to the dispatcher is easy:
</p>
        <pre class="code">
          <span style="color: blue">var </span>saveDocumentRequest = <span style="color: blue">new </span><span style="color: #2b91af">SaveDocumentRequest</span>(); <span style="color: blue">var </span>getRemainingDocuments
= <span style="color: blue">new </span><span style="color: #2b91af">GetRemainingDocumentsRequest</span>();
dispatcher.Add(saveDocumentRequest, getRemainingDocuments);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
 
</p>
        <p>
Where the signature of the Add method in Dispatcher is like;
</p>
        <pre class="code">
          <span style="color: blue">public void </span>Add(<span style="color: blue">params </span><span style="color: #2b91af">Request</span>[]
requests)</pre>
        <p>
        </p>
        <p>
Although this syntax is not bad, it feels like so much like code from last month:
not very sexy. Wouldn't be more fun if we could spice it up a bit using generics and
a bit of Func?
</p>
        <p>
I'd love to get rid of instantiating a variable just for the sake of adding it to
my dispatcher. After a bit of fiddling around with my unit tests I came up with the
following solution.
</p>
        <p>
What I want is to call the Add method in a generic way and set the parameters on my
request object inline, using a Func. This is best illustrated with a test:
</p>
        <pre class="code">[<span style="color: #2b91af">Test</span>] <span style="color: blue">public
void </span>can_assign_value_using_a_func_in_a_generic_method_call() { <span style="color: #2b91af">Guid </span>id
= <span style="color: #2b91af">Guid</span>.NewGuid(); <span style="color: blue">var </span>dispatcher
= <span style="color: blue">new </span><span style="color: #2b91af">Dispatcher</span>();
dispatcher.Add&lt;<span style="color: #2b91af">GetPersonsRequest</span>&gt;(s =&gt;
s.ID = id); <span style="color: green">//disregard ugly cast; this is only for test
purposes </span><span style="color: blue">var </span>request = (<span style="color: #2b91af">GetPersonsRequest</span>)dispatcher.Requests.First();
request.ID.ShouldEqual(id); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>Where the Request and dispatcher have
these signatures: 
<br /><pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">GetPersonsRequest</span>:<span style="color: #2b91af">Request </span>{ <span style="color: blue">public </span><span style="color: #2b91af">Guid </span>ID
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } } <span style="color: blue">public
class </span><span style="color: #2b91af">Dispatcher </span>{ <span style="color: blue">public </span>Dispatcher()
{ Requests = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">Request</span>&gt;();
} <span style="color: blue">public void </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)<br /><span style="color: blue">where </span>TRequestType : <span style="color: #2b91af">Request</span>, <span style="color: blue">new</span>()
{ <span style="color: blue">var </span>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(request); } Requests.Add(request); } <span style="color: blue">public </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">Request</span>&gt;
Requests { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} }</pre><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><p>
I can now set only property in my Request type, what if it has more properties that
need to be set? Just introduce the infamous params to the method signature like so:
</p><pre class="code"><span style="color: blue">public void </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) 
<br /><span style="color: blue">where </span>TRequestType:<span style="color: #2b91af">Request</span>, <span style="color: blue">new</span>()
{ <span style="color: blue">var </span>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(request); } Requests.Add(request); }</pre><p><a href="http://11011.net/software/vspaste"></a></p><p>
And again the test:
</p><pre class="code">[<span style="color: #2b91af">Test</span>] <span style="color: blue">public
void </span>can_assign_two_values_using_a_func_in_a_generic_method_call() { <span style="color: blue">var </span>dispatcher
= <span style="color: blue">new </span><span style="color: #2b91af">Dispatcher</span>(); <span style="color: #2b91af">Guid </span>id
= <span style="color: #2b91af">Guid</span>.NewGuid(); dispatcher.Add&lt;<span style="color: #2b91af">GetPersonsRequest</span>&gt;(s
=&gt; s.ID = id, t=&gt; t.GetAllDetails = <span style="color: blue">true</span>); <span style="color: green">//disregard
ugly cast; this is only for test purposes </span><span style="color: blue">var </span>request
= (<span style="color: #2b91af">GetPersonsRequest</span>)dispatcher.Requests.First();
request.ID.ShouldEqual(id); request.GetAllDetails.ShouldBeTrue(); }</pre><a href="http://11011.net/software/vspaste"></a><p>
When we change the return type of the Add method to the dispatcher itself, we can
then use a fluent interface to get a very friendly syntax  for making calls:
</p><p>
 
</p><pre class="code"><span style="color: green">//input parameters for first request </span><span style="color: blue">var </span>document
= <span style="color: blue">new object</span>(); <span style="color: blue">var </span>userID
= <span style="color: #2b91af">Guid</span>.NewGuid(); <span style="color: green">//input
parameters for second request </span><span style="color: blue">var </span>dossierID
= <span style="color: #2b91af">Guid</span>.NewGuid(); dispatcher .Add&lt;<span style="color: #2b91af">SaveDocumentRequest</span>&gt;(s
=&gt; s.Document = document, t =&gt; t.UserID = userID) .Add&lt;<span style="color: #2b91af">GetZaakRequest</span>&gt;(s
=&gt; s.DossierId = dossierID);</pre><p>
I really like the fact that I don't have to initialize a variable and still have access
to all the properties in the request object..
</p><img width="0" height="0" src="http://www.tjsolutions.nl/aggbug.ashx?id=da163853-8db7-45bf-a157-9c0058030aa3" /></body>
      <title>Functional programming with the Request/Response Service Layer</title>
      <guid isPermaLink="false">http://www.tjsolutions.nl/PermaLink,guid,da163853-8db7-45bf-a157-9c0058030aa3.aspx</guid>
      <link>http://www.tjsolutions.nl/2009/10/31/FunctionalProgrammingWithTheRequestResponseServiceLayer.aspx</link>
      <pubDate>Sat, 31 Oct 2009 16:54:24 GMT</pubDate>
      <description>&lt;p&gt;
At my current project we are using a dispatcher class to batch requests to our WCF
layer based on the &lt;a href="http://davybrion.com/blog/2009/11/requestresponse-service-layer-series/"&gt;Request/Response
Service Layer&lt;/a&gt; created by Davy Brion. Once you call the Get&amp;lt;TResponseType&amp;gt;()
on the dispatcher the WCF layer starts working on the requests one by one and return
them in one roundtrip.
&lt;/p&gt;
&lt;p&gt;
Adding requests to the dispatcher is easy:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;saveDocumentRequest = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SaveDocumentRequest&lt;/span&gt;(); &lt;span style="color: blue"&gt;var &lt;/span&gt;getRemainingDocuments
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GetRemainingDocumentsRequest&lt;/span&gt;();
dispatcher.Add(saveDocumentRequest, getRemainingDocuments);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Where the signature of the Add method in Dispatcher is like;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;Add(&lt;span style="color: blue"&gt;params &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Request&lt;/span&gt;[]
requests)&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Although this syntax is not bad, it feels like so much like code from last month:
not very sexy. Wouldn't be more fun if we could spice it up a bit using generics and
a bit of Func?
&lt;/p&gt;
&lt;p&gt;
I'd love to get rid of instantiating a variable just for the sake of adding it to
my dispatcher. After a bit of fiddling around with my unit tests I came up with the
following solution.
&lt;/p&gt;
&lt;p&gt;
What I want is to call the Add method in a generic way and set the parameters on my
request object inline, using a Func. This is best illustrated with a test:
&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;can_assign_value_using_a_func_in_a_generic_method_call() { &lt;span style="color: #2b91af"&gt;Guid &lt;/span&gt;id
= &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid(); &lt;span style="color: blue"&gt;var &lt;/span&gt;dispatcher
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dispatcher&lt;/span&gt;();
dispatcher.Add&amp;lt;&lt;span style="color: #2b91af"&gt;GetPersonsRequest&lt;/span&gt;&amp;gt;(s =&amp;gt;
s.ID = id); &lt;span style="color: green"&gt;//disregard ugly cast; this is only for test
purposes &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;request = (&lt;span style="color: #2b91af"&gt;GetPersonsRequest&lt;/span&gt;)dispatcher.Requests.First();
request.ID.ShouldEqual(id); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Where the Request and dispatcher have
these signatures: 
&lt;br /&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GetPersonsRequest&lt;/span&gt;:&lt;span style="color: #2b91af"&gt;Request &lt;/span&gt;{ &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Guid &lt;/span&gt;ID
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } } &lt;span style="color: blue"&gt;public
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dispatcher &lt;/span&gt;{ &lt;span style="color: blue"&gt;public &lt;/span&gt;Dispatcher()
{ Requests = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Request&lt;/span&gt;&amp;gt;();
} &lt;span style="color: blue"&gt;public void &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;br /&gt;
&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;()
{ &lt;span style="color: blue"&gt;var &lt;/span&gt;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(request); } Requests.Add(request); } &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Request&lt;/span&gt;&amp;gt;
Requests { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;;
} }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
I can now set only property in my Request type, what if it has more properties that
need to be set? Just introduce the infamous params to the method signature like so:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &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;br /&gt;
&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;()
{ &lt;span style="color: blue"&gt;var &lt;/span&gt;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(request); } Requests.Add(request); }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
And again the test:
&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;can_assign_two_values_using_a_func_in_a_generic_method_call() { &lt;span style="color: blue"&gt;var &lt;/span&gt;dispatcher
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dispatcher&lt;/span&gt;(); &lt;span style="color: #2b91af"&gt;Guid &lt;/span&gt;id
= &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid(); dispatcher.Add&amp;lt;&lt;span style="color: #2b91af"&gt;GetPersonsRequest&lt;/span&gt;&amp;gt;(s
=&amp;gt; s.ID = id, t=&amp;gt; t.GetAllDetails = &lt;span style="color: blue"&gt;true&lt;/span&gt;); &lt;span style="color: green"&gt;//disregard
ugly cast; this is only for test purposes &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;request
= (&lt;span style="color: #2b91af"&gt;GetPersonsRequest&lt;/span&gt;)dispatcher.Requests.First();
request.ID.ShouldEqual(id); request.GetAllDetails.ShouldBeTrue(); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
When we change the return type of the Add method to the dispatcher itself, we can
then use a fluent interface to get a very friendly syntax&amp;#160; for making calls:
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//input parameters for first request &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;document
= &lt;span style="color: blue"&gt;new object&lt;/span&gt;(); &lt;span style="color: blue"&gt;var &lt;/span&gt;userID
= &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid(); &lt;span style="color: green"&gt;//input
parameters for second request &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;dossierID
= &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid(); dispatcher .Add&amp;lt;&lt;span style="color: #2b91af"&gt;SaveDocumentRequest&lt;/span&gt;&amp;gt;(s
=&amp;gt; s.Document = document, t =&amp;gt; t.UserID = userID) .Add&amp;lt;&lt;span style="color: #2b91af"&gt;GetZaakRequest&lt;/span&gt;&amp;gt;(s
=&amp;gt; s.DossierId = dossierID);&lt;/pre&gt;
&lt;p&gt;
I really like the fact that I don't have to initialize a variable and still have access
to all the properties in the request object..
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tjsolutions.nl/aggbug.ashx?id=da163853-8db7-45bf-a157-9c0058030aa3" /&gt;</description>
      <comments>http://www.tjsolutions.nl/CommentView,guid,da163853-8db7-45bf-a157-9c0058030aa3.aspx</comments>
      <category>.NET</category>
      <category>Functional</category>
      <category>Linq</category>
    </item>
  </channel>
</rss>