<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2051886115581731342</atom:id><lastBuildDate>Mon, 16 Jan 2012 13:06:46 +0000</lastBuildDate><category>Python</category><category>wizard</category><category>IoC</category><category>pjsip4net</category><category>patterns</category><category>ESB</category><category>Rails</category><category>CAB</category><category>localization</category><category>messaging</category><category>voip</category><category>sip</category><category>XAML</category><category>DI</category><category>C#</category><category>queue</category><category>RSpec</category><category>NServiceBus</category><category>Caliburn</category><category>sql</category><category>git</category><category>powershell</category><category>Castle Windsor</category><category>Ruby</category><category>Django</category><category>DM-V-VM</category><category>WPF</category><category>nhibernate</category><title>Roblog</title><description /><link>http://robbbloggg.blogspot.com/</link><managingEditor>noreply@blogger.com (RobertT)</managingEditor><generator>Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/robbbloggg" /><feedburner:info uri="blogspot/robbbloggg" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-4194062547973144084</guid><pubDate>Mon, 16 Jan 2012 13:04:00 +0000</pubDate><atom:updated>2012-01-16T05:06:46.401-08:00</atom:updated><title>How do you tell a good code?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Agree with Ayende:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;"... most good code bases are actually fairly boring. That is pretty much the definition of a good codebase..."&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://ayende.com/blog/153697/a-meta-post-about-negative-code-reviews"&gt;Source&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; text-align: -webkit-auto;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Good luck!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-4194062547973144084?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=7O96Ek7Cppg:U_w1mMAHQNA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=7O96Ek7Cppg:U_w1mMAHQNA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/7O96Ek7Cppg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/7O96Ek7Cppg/how-do-you-tell-good-code.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2012/01/how-do-you-tell-good-code.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-6141416812718931144</guid><pubDate>Sun, 15 Jan 2012 20:31:00 +0000</pubDate><atom:updated>2012-01-15T12:34:43.369-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ruby</category><category domain="http://www.blogger.com/atom/ns#">RSpec</category><category domain="http://www.blogger.com/atom/ns#">Rails</category><title>Speed up rails3 rspec2</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;If you've eventually fell asleep while waiting for your test suits to run, here's a good description on how to&amp;nbsp;&lt;a href="http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html"&gt;speed it up&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;PS One little nitpick: all of the spork commands should be executed in bundle exec context as long we use bundler insted of rubygems.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-6141416812718931144?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=wh_lej9sXMQ:zPbNVuqEeeA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=wh_lej9sXMQ:zPbNVuqEeeA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/wh_lej9sXMQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/wh_lej9sXMQ/speed-up-rails3-rspec2.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2012/01/speed-up-rails3-rspec2.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-4574844628671280125</guid><pubDate>Tue, 13 Sep 2011 07:31:00 +0000</pubDate><atom:updated>2011-09-13T00:33:41.049-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">powershell</category><title>Calculate LOC with one line of code</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Found a very useful tip on how to quickly estimate the size of a project with only one line of powershell script.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Navigate to the root directory of your project and in powershell type the following:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(dir -include *.cs,*.xaml -recurse | select-string .).Count&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Thats it.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Good luck!&lt;/span&gt;&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-4574844628671280125?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=nC7l2pEjBLY:Xv2RrxngWFk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=nC7l2pEjBLY:Xv2RrxngWFk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/nC7l2pEjBLY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/nC7l2pEjBLY/calculate-loc-with-one-line-of-code.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/09/calculate-loc-with-one-line-of-code.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-2962203520114519082</guid><pubDate>Thu, 11 Aug 2011 21:23:00 +0000</pubDate><atom:updated>2011-08-11T14:24:11.684-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Caliburn</category><title>Execute Caliburn coroutine in action pipeline without UI trigger</title><description>&lt;span class="Apple-style-span"  &gt;Seems rather easy, isn't it? &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Just put it into Presenter's Execute method and the did is done. Well, should it be like that I wouldn't wake up in the night and write this stuff!
&lt;br /&gt;Let's see what's there in Execute:
&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/TRyBqxFhS7I/AAAAAAAAMPc/fuX2ODzwnj8/s1600/Execute.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor: pointer; width: 400px; height: 114px;" src="http://3.bp.blogspot.com/_aPBCtYeet9E/TRyBqxFhS7I/AAAAAAAAMPc/fuX2ODzwnj8/s400/Execute.png" alt="" id="BLOGGER_PHOTO_ID_5556458611999329202" border="0" /&gt;&lt;/a&gt;
&lt;br /&gt;So, it just packs every single coroutine it has in SequentialResult and execute 'em. No filters pipeline used, no routedMessage. None of your neat filters applied to these coroutines.
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;You might ask what is the difference with executing coroutines as a result of some UI action, be it a routed event or a command. The answer is in the Caliburn.PresentationFramework.Actions namespace.
&lt;br /&gt;To be prrecise it is an Action Execute overloaded method that in simple case of SynchronousAction does the following:
&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/TRyD11060MI/AAAAAAAAMPs/AlHasxeE4RU/s1600/Action.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor: pointer; width: 400px; height: 164px;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/TRyD11060MI/AAAAAAAAMPs/AlHasxeE4RU/s400/Action.png" alt="" id="BLOGGER_PHOTO_ID_5556461001273692354" border="0" /&gt;&lt;/a&gt;
&lt;br /&gt;namely calls preprocessor filters, delegates a call to method that might be returning coroutine, handles errors with rescue filters, calls postprocessor filters. That is a filter pipeline I am talking about.
&lt;br /&gt;Well, seems that Caliburn has everything I need. And all I have to do is just use it. &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;As header states there is no UI trigger, i.e. I want to execute a coroutine when nobody clicked a button, but rather on some external trigger. As an example, consider model update with call to any data storage during Presenter initialization stage.
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Enter DegenerateMessage. This intellectual piece of code is a data container that is being handed to participants on courutine call pipeline in order to hint what was the original method name called.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;img src="http://2.bp.blogspot.com/-u6-xGewWtwI/TkPUu3TFvlI/AAAAAAAAMWE/RUPA_VSn6Z0/s400/DegenerateMessage.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5639585059981082194" style="cursor: pointer; width: 332px; height: 400px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Another intellectual piece of code is DegenerateMessageTrigger. It is so damn smart that it knows that in order to trigger an action it has to pass a message to message handler!  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;img src="http://1.bp.blogspot.com/-jUrePoV1ek8/TkPUu0y4iwI/AAAAAAAAMWM/cIFQj4aL6zU/s400/DegenerateTrigger.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5639585059309128450" style="cursor: pointer; width: 400px; height: 211px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;And yet another piece is a DegenerateMessageHandler. It really shouldn't be called that way as it performs really complicated things. Namely, it creates an ActionHost and when Process is called converts DegenerateMessage to an ActionMessage and put it into the standard Caliburn action pipeline.  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;img src="http://2.bp.blogspot.com/-4sxOZ2gQhKM/TkPUujZiknI/AAAAAAAAMV8/0u8x1086KmU/s400/DegenerateHandler.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5639585054639428210" style="cursor: pointer; width: 397px; height: 400px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;If it seems like dancing on your head, then know that you are not alone. But wait, there is another part I forgot to mention. It is a simple interface IResultExecutor aimed to hide all that smart code under two methods accepting Expressions with lambdas calling methods that return coroutines.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Oh, and there is yet another thing. With &lt;a href="http://caliburnmicro.codeplex.com/"&gt;Caliburn Micro&lt;/a&gt; you can accomplish the same with &lt;a href="http://mikaelkoskinen.net/post/caliburn-micro-wp7-coroutines-without-user-input.aspx"&gt;only one line of code&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;
&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Cheers! &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-2962203520114519082?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=P5D5R2UzlDc:TzutfrvX-8I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=P5D5R2UzlDc:TzutfrvX-8I:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/P5D5R2UzlDc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/P5D5R2UzlDc/execute-caliburn-coroutine-in-action.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_aPBCtYeet9E/TRyBqxFhS7I/AAAAAAAAMPc/fuX2ODzwnj8/s72-c/Execute.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/08/execute-caliburn-coroutine-in-action.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-5990515185288212543</guid><pubDate>Thu, 04 Aug 2011 07:01:00 +0000</pubDate><atom:updated>2011-08-04T00:02:04.634-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">queue</category><category domain="http://www.blogger.com/atom/ns#">messaging</category><category domain="http://www.blogger.com/atom/ns#">ESB</category><title>The best explanation to ESB ever.</title><description>&lt;span class="Apple-style-span"  &gt;I've finally managed to reread some of old Udi's &lt;a href="http://www.udidahan.com/2007/04/28/the-enterprise-service-bus-and-your-soa/"&gt;articles&lt;/a&gt; and suddenly realized that following few lines are the best explanation of what ESB is all about, ever.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;I never want to miss it again that is why I repost it right here in my blog.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;i&gt;"&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); "&gt;it’s all in the message. Forget about remote method invocations and pub-subbing events—down on the wire it’s all just messages. The trick is to think of your system as passing messages at the application level as well.&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); "&gt;&lt;span class="Apple-style-span"  &gt;&lt;i&gt;&lt;p&gt;Asynchronous message passing over queues. It’s really quite simple.&lt;/p&gt;&lt;p&gt;Once you’ve packaged everything into the message, that message can be dynamically routed anywhere, and so can its responses. The application doesn’t need to bind against any specific endpoint—it just drops a message addressed to some logical location. Infrastructure can make sure that messages get to the logical recipient, even if they change physical locations.&lt;/p&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;i&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); "&gt;That infrastructure is what brings about the “Bus” architectural style between your distributed components.&lt;/span&gt;"&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;As Udi says, you have to reread it several dozens of times, until it strikes to you.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-5990515185288212543?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=3SM5neMk1FM:cZabos6C0CQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=3SM5neMk1FM:cZabos6C0CQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/3SM5neMk1FM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/3SM5neMk1FM/best-explanation-to-esb-ever.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/08/best-explanation-to-esb-ever.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-6750350821219641520</guid><pubDate>Tue, 19 Jul 2011 20:03:00 +0000</pubDate><atom:updated>2011-07-19T13:50:33.626-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">git</category><title>Git ftp deploy</title><description>&lt;span class="Apple-style-span"  &gt;With tools like git, NServiceBus, RoR and the rest, life seams to be better then ever.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;With git I've managed to setup deployment with a matter of minutes. Just like this: &lt;a href="http://blog.wekeroad.com/2009/11/23/deploying-a-web-application-with-git-and-ftp"&gt;http://blog.wekeroad.com/2009/11/23/deploying-a-web-application-with-git-and-ftp&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;There are other ways, probably even simplier: &lt;a href="http://ayende.com/blog/4836/primitive-git-auto-deploy"&gt;http://ayende.com/blog/4836/primitive-git-auto-deploy&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-6750350821219641520?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=FF_EW-wcM5Y:0_TJMiznNJ4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=FF_EW-wcM5Y:0_TJMiznNJ4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/FF_EW-wcM5Y" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/FF_EW-wcM5Y/git-ftp-deploy.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/07/git-ftp-deploy.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-7366057357030350340</guid><pubDate>Sun, 05 Jun 2011 19:17:00 +0000</pubDate><atom:updated>2011-06-05T12:17:40.420-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Django</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Django newby frustrations.</title><description>&lt;span class="Apple-style-span"  &gt;As you might already guessed, I am currently in a process of discovering two technologies I had no experience with before. &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;This time I met a strange error running a Django tutorial web application: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0...&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;The simplest solution to this can be found here: &lt;a href="http://victor-k-development.blogspot.com/2010/07/unicodedecodeerror-django.html"&gt;http://victor-k-development.blogspot.com/2010/07/unicodedecodeerror-django.html&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;But the roots of the problem and an ultimate solution are to be found here: &lt;a href="http://stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe0-in-position-0-ordinal"&gt;http://stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe0-in-position-0-ordinal&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-7366057357030350340?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=mu0eBPp8asg:P_puk5LaUoc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=mu0eBPp8asg:P_puk5LaUoc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/mu0eBPp8asg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/mu0eBPp8asg/django-newby-frustrations.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/06/django-newby-frustrations.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-7224761589655169303</guid><pubDate>Sun, 05 Jun 2011 13:02:00 +0000</pubDate><atom:updated>2011-06-05T06:02:41.293-07:00</atom:updated><title>RoR newby frustrations</title><description>&lt;span class="Apple-style-span"  &gt;As usual, trying to adopt something new is really is a frustration. And though Rails is about to be "&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); line-height: 22px; "&gt;a breakthrough in lowering the barriers of entry to programming&lt;/span&gt;" you will defenitely meet some errors that might stop you on your way.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;First thing I met was: "[rake --tasks] rake aborted! no such file to load -- sqlite3/sqlite3_native".&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;The solution is really simple. Rake is telling you that it can't find a native library for sqlite. Well, just do what you've been told. Give it a sqlite.dll/.so (depends on OS you are). Put it in $ruby_home\bin.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Next thing to immedeately pop up, after I gave it what it wanted was: "[rake --tasks] WARNING: Global access to Rake DSL methods is deprecated." This one is not as obvious as former. Solution to this one is desribed here: &lt;a href="http://benwoodall.com/2011/06/rails-global-access-to-rake-dsl-methods-is-deprecated/"&gt;http://benwoodall.com/2011/06/rails-global-access-to-rake-dsl-methods-is-deprecated/&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;That's it for now.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;a href="http://benwoodall.com/2011/06/rails-global-access-to-rake-dsl-methods-is-deprecated/"&gt;&lt;/a&gt;Good luck! &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-7224761589655169303?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=tjtKmsq66N0:hDAhhdqVbh8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=tjtKmsq66N0:hDAhhdqVbh8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/tjtKmsq66N0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/tjtKmsq66N0/ror-newby-frustrations.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/06/ror-newby-frustrations.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-5828698722483299627</guid><pubDate>Wed, 01 Jun 2011 16:26:00 +0000</pubDate><atom:updated>2011-06-01T09:27:13.071-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ruby</category><category domain="http://www.blogger.com/atom/ns#">Rails</category><title>Installing rails on windows</title><description>&lt;span class="Apple-style-span"  &gt;If you tried to install rails with gems and failed with message "...No such file or directory" - dont woly be hapy. Just folllow these instructions: &lt;a href="http://stackoverflow.com/questions/849660/how-to-stop-the-gem-utility-from-accessing-my-home-directory"&gt;http://stackoverflow.com/questions/849660/how-to-stop-the-gem-utility-from-accessing-my-home-directory&lt;/a&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-5828698722483299627?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=EcX90QZ2-FE:UsWb_qDeHA0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=EcX90QZ2-FE:UsWb_qDeHA0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/EcX90QZ2-FE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/EcX90QZ2-FE/installing-rails-on-windows.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/06/installing-rails-on-windows.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-6672423846935572060</guid><pubDate>Tue, 24 May 2011 13:28:00 +0000</pubDate><atom:updated>2011-05-24T06:40:29.050-07:00</atom:updated><title>JetBrains dotPeek to rescue.</title><description>&lt;span class="Apple-style-span"  &gt;I don't know how you faced the fact that Reflector is no longer free, but I for one was very-very dissapointed. Now, our favorite JetBrains team comes to rescue with their brand new tool called dotPeek.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Go and get it &lt;a href="http://www.jetbrains.com/decompiler/"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;PS. Five minutes later I found another tool that will compete to take Reflector's place - JustDecompile from Telerik. It is &lt;a href="http://www.telerik.com/products/decompiling.aspx"&gt;here&lt;/a&gt;. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;PPS. Also, there is a work being done for Silverlight by &lt;a href="http://denisvuyka.wordpress.com/2011/04/27/il-view-net-reflector-oss-alternative-in-silverlight/"&gt;Denis Vuyka&lt;/a&gt; and there is another OSS tool to compete for our souls - &lt;a href="http://wiki.sharpdevelop.net/ilspy.ashx"&gt;ILSpy&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;PPPS. Life is good again.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Good luck.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-6672423846935572060?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=Wsp3ViKz9tc:2jso7MC4w40:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=Wsp3ViKz9tc:2jso7MC4w40:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/Wsp3ViKz9tc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/Wsp3ViKz9tc/jetbrains-dotpeek-to-rescue.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/05/jetbrains-dotpeek-to-rescue.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-3024602484239778614</guid><pubDate>Mon, 16 May 2011 08:48:00 +0000</pubDate><atom:updated>2011-05-16T02:44:58.819-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">NServiceBus</category><title>NServiceBus Saga Idempotency</title><description>&lt;span class="Apple-style-span"&gt;Should your business entities had a natural identifier (I think even a surrogate one would do in this case), it would be trivial to ensure idempotency of sagas, that drive their processing.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;Just store that Id in a temporal saga storage and enqueue a handler that will guard your sagas as the first handler in NServiceBus endpoint pipe. Something like this one:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;img src="http://4.bp.blogspot.com/-hgpPcrcN7h8/TdDkNUJUMJI/AAAAAAAAMSs/xRXy3duW9PM/s400/handler.png" style="cursor:pointer; cursor:hand;width: 400px; height: 98px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5607232453473480850" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;And don't forget to specify message handling order:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;img src="http://1.bp.blogspot.com/-tnFca_FaAro/TdDkNYFpZXI/AAAAAAAAMSk/jrx1um0MNWc/s400/config.png" style="cursor:pointer; cursor:hand;width: 400px; height: 98px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5607232454531835250" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-3024602484239778614?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=SpXibXpqcPU:i6ITOn1pZLU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=SpXibXpqcPU:i6ITOn1pZLU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/SpXibXpqcPU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/SpXibXpqcPU/nservicebus-saga-idempotency.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-hgpPcrcN7h8/TdDkNUJUMJI/AAAAAAAAMSs/xRXy3duW9PM/s72-c/handler.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2011/05/nservicebus-saga-idempotency.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-2924535837840329425</guid><pubDate>Thu, 07 Oct 2010 13:40:00 +0000</pubDate><atom:updated>2010-10-11T01:03:35.907-07:00</atom:updated><title>Applying monadic combinators to build simple parser</title><description>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;After reading &lt;a href="http://blogs.msdn.com/b/lukeh/archive/2007/08/19/monadic-parser-combinators-using-c-3-0.aspx"&gt;this article&lt;/a&gt;, it dawned on me, how easy it might be to write parsers using internal dsl syntax. Looks a bit clumsy in C#, yet rather expressive.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;I've used wonderful &lt;a href="http://www.ohloh.net/p/magnum"&gt;Magnum&lt;/a&gt; &lt;a href="http://code.google.com/p/magnum/"&gt;library &lt;/a&gt;built by &lt;a href="http://drusellers.com/"&gt;Dru Sellers&lt;/a&gt; and &lt;a href="http://code.google.com/p/magnum/people/detail?u=ChrisFromTulsa"&gt;Chris&lt;/a&gt; (creators of open source service bus MassTransit project) as a foundation, since it already contains a base for monadic parsers.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;As an example, look how easy it is to write a parser for following simple grammar, describing file version structure:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&amp;lt;version&amp;gt; ::= &amp;lt;part&amp;gt;{&amp;lt;delim&amp;gt;&amp;lt;part&amp;gt;|&amp;lt;part&amp;gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&amp;lt;part&amp;gt; ::= &amp;lt;positive integer&amp;gt;+ | &amp;lt;letter&amp;gt;+&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&amp;lt;delim&amp;gt; ::= “.” | “,” | “(” | “)” | “ “&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;And parser in mere 10 lines of code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://2.bp.blogspot.com/_aPBCtYeet9E/TLLAp466AGI/AAAAAAAAMN4/iN-IYloqHEI/s1600/versionparser.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 259px;" src="http://2.bp.blogspot.com/_aPBCtYeet9E/TLLAp466AGI/AAAAAAAAMN4/iN-IYloqHEI/s400/versionparser.png" alt="" id="BLOGGER_PHOTO_ID_5526691518623645794" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Good luck!&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-2924535837840329425?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=F_3v6wFAe_s:VJJZ5O_9LH8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=F_3v6wFAe_s:VJJZ5O_9LH8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/F_3v6wFAe_s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/F_3v6wFAe_s/applying-monadic-combinators-to-build.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_aPBCtYeet9E/TLLAp466AGI/AAAAAAAAMN4/iN-IYloqHEI/s72-c/versionparser.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2010/10/applying-monadic-combinators-to-build.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-6934803763045122909</guid><pubDate>Tue, 21 Sep 2010 19:05:00 +0000</pubDate><atom:updated>2010-09-21T12:41:01.975-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">patterns</category><title>Dependency injection</title><description>Below is a presentation I've recently made for my colleagues.&lt;br /&gt;&lt;br /&gt;My fellow java developer exclaimed: "But this is ridiculous to make presentations about DI! Everybody supposed to know it!" And this is a big &lt;a href="http://davybrion.com/blog/2009/04/at-this-point-id-prefer-java-developers-over-net-developers/"&gt;difference&lt;/a&gt; between two worlds &lt;a href="http://davybrion.com/blog/2010/08/how-i-feel-about-the-net-world-lately/"&gt;.Net &amp;amp; Java&lt;/a&gt;. In java even junior developers know benefits of DI, whereas you can find a senior developer having no knowledge of DI in .Net realm. I consider it to be a consequence of paying &lt;a href="http://ayende.com/Blog/archive/2010/08/03/microsoft.data-because-the-90s-were-so-good-we-want-to.aspx"&gt;way to much attention&lt;/a&gt; to developers' tools by Microsoft. &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch"&gt;LightSwitch&lt;/a&gt; and &lt;a href="http://www.asp.net/webmatrix"&gt;WebMatrix&lt;/a&gt; are a justification to my words. Hey guys, do you really think we are that stupid? Why constantly &lt;a href="http://ayende.com/Blog/archive/2010/08/04/microsoft.data-and-positioning.aspx"&gt;lower the bar&lt;/a&gt;?&lt;br /&gt;&lt;br /&gt;Nevertheles, if you are interested, check it out and browse for code examples that come with my presentation.&lt;div style="width: 425px;" id="__ss_5250166"&gt;&lt;strong style="margin: 12px 0pt 4px; display: block;"&gt;&lt;a href="http://www.slideshare.net/siniypin/dependency-injection" title="Dependency injection"&gt;Dependency injection&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse5250166" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dependencyinjectiondi-100921100133-phpapp02&amp;amp;stripped_title=dependency-injection&amp;amp;userName=siniypin"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed name="__sse5250166" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dependencyinjectiondi-100921100133-phpapp02&amp;amp;stripped_title=dependency-injection&amp;amp;userName=siniypin" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="padding: 5px 0pt 12px;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://rapidshare.com/files/420416655/DI.rar"&gt;Code&lt;/a&gt; as I promised.&lt;br /&gt;&lt;br /&gt;Good luck!&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-6934803763045122909?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=Q585Cw490s8:WEbK0lo0khg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=Q585Cw490s8:WEbK0lo0khg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/Q585Cw490s8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/Q585Cw490s8/dependency-injection.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2010/09/dependency-injection.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-1151370478677666544</guid><pubDate>Sun, 12 Sep 2010 20:57:00 +0000</pubDate><atom:updated>2010-09-12T14:46:54.152-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">IoC</category><category domain="http://www.blogger.com/atom/ns#">DI</category><category domain="http://www.blogger.com/atom/ns#">Castle Windsor</category><title>Windsor Castle BuildUp</title><description>&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Good news, everyone! I've discovered a way to enhance a brilliant &lt;a href="http://using.castleproject.org/display/IoC/Home"&gt;DI-container Castle Windsor&lt;/a&gt; with not so brilliant feature as BuildUp.&lt;br /&gt;&lt;br /&gt;Saying that it is not that brilliant I mean that this feature is a beast, actually. It is an open door to violate DI principles, and there are more elegant ways to overcome a problem of having to resolve an external object through DI-container. After all, if Castle team considered this feature useful, they would roll it out long time ago, have no doubt!&lt;br /&gt;However, in my case it is a matter of time, to have an opportunity of resolving existing object's dependencies through DI-container, built as fast as possible. That is why I turned to BuildUp feature that some &lt;a href="http://msdn.microsoft.com/en-us/library/ff649576.aspx"&gt;other DI-frameworks have&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I was really amused with Windsor's &lt;a href="http://using.castleproject.org/display/IoC/Extension+points"&gt;degree of extendability&lt;/a&gt; and how trivial my solution appeared.&lt;br /&gt;&lt;br /&gt;BuildUp functionality is closed up under &lt;a href="http://www.tunatoksoz.com/post/Castle-Custom-Component-Activators.aspx"&gt;ComponentActivator&lt;/a&gt;. Activators are called when LifetimeManager considers that a new object has to be created. And that logically brings us to restriction of this solution - it won't work with Singleton lifestyle. But it shouldn't actually! When you mark an object as a singleton - you effectively state that a container is going to be an owner of that object, thus it won't ever be built externally.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_aPBCtYeet9E/TF_qdgcGqJI/AAAAAAAAMMQ/LI-7xh6IiJw/s1600/BuildUpActivator.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 178px;" src="http://2.bp.blogspot.com/_aPBCtYeet9E/TF_qdgcGqJI/AAAAAAAAMMQ/LI-7xh6IiJw/s400/BuildUpActivator.png" alt="" id="BLOGGER_PHOTO_ID_5503375062314952850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;BuildUpComponentActivator extends &lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;DefaultComponentActivator &lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;and overrides a single method - Instantiate. This guy is a cheater, as you might guess, it never creates an object, but simply read it from context. All the dirty job of deriving dependencies is done by a parent class.&lt;/span&gt; &lt;span style=";font-family:verdana;font-size:85%;"  &gt;Should &lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;BuildUpComponentActivator &lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt; fail to find an object in context, it will simply delegate all work to parent, and a new object will be created.&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt; This is done to support resolving objects of the same type managed by container.&lt;br /&gt;&lt;br /&gt;Context is a dictionary, created with BuildUp extension method:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_aPBCtYeet9E/TF_qd3zbkEI/AAAAAAAAMMY/wp7I6xB6IVM/s1600/BuildUpContainerExt.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 117px;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/TF_qd3zbkEI/AAAAAAAAMMY/wp7I6xB6IVM/s400/BuildUpContainerExt.png" alt="" id="BLOGGER_PHOTO_ID_5503375068586807362" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In order to be able to build up an object, one have to modify it's registration and override ComponentActivator setting. CanBeBuiltUp is a neat extension method wrapping this call for Windsor fluent registration API.&lt;br /&gt;&lt;br /&gt;There is only one shortcoming with this solution I came with - it doesn't provide you with any facilities to release this external object's dependencies. It has to be done manually somewhere.&lt;br /&gt;&lt;br /&gt;Please note, that there are &lt;a href="http://www.primordialcode.com/blog/post/castle-windsor-resolve-dependencies-existing-object-instance"&gt;other solutions to this problem&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Good luck!&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-1151370478677666544?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=xcVqjujo_e0:-QDJGA53cjE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=xcVqjujo_e0:-QDJGA53cjE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/xcVqjujo_e0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/xcVqjujo_e0/windsor-castle-buildup.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_aPBCtYeet9E/TF_qdgcGqJI/AAAAAAAAMMQ/LI-7xh6IiJw/s72-c/BuildUpActivator.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2010/09/windsor-castle-buildup.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-48009709978359465</guid><pubDate>Mon, 30 Aug 2010 19:10:00 +0000</pubDate><atom:updated>2011-05-16T01:51:38.917-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">sip</category><category domain="http://www.blogger.com/atom/ns#">voip</category><category domain="http://www.blogger.com/atom/ns#">pjsip4net</category><title>My two cents in OSS. Free VOIP .Net library.</title><description>&lt;span  &gt;Good news, everyone!&lt;br /&gt;&lt;br /&gt;A brand new pure OOP VOIP open souce library has just entered the .Net realm - pjsip4net. This is my projection of plain "2D" procedural C library &lt;a href="http://www.pjsip.org/"&gt;pjsip&lt;/a&gt; into "3D" world of objects. It is so trendy to go 3D nowadays that I just couldn't resist. =)&lt;br /&gt;&lt;br /&gt;To be correct pjsip4net is a wrapper above high-level &lt;a href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB.htm"&gt;pjsua&lt;/a&gt; API. It provides you with readymade user agent capable to issue calls over SIP &amp;amp; (S)RTP protocols via UDP or TCP or even TLS from your .Net code.&lt;br /&gt;&lt;br /&gt;Actually, this code is still under construction due to my constant need to improve. But keep your wig on, it is already usable and tested.&lt;br /&gt;&lt;br /&gt;I have covered prety much everything in pjsua API, but still this is what you can do with it:&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span  &gt;register at SIP server;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;select a sound device;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;select and prioritize codecs;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;call another party;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;auto answer;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;auto conference (all calls will be marshalled to one big conference);&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;NAT traversal (STUN, TURN, ICE);&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span  &gt;&lt;span&gt;blah blah blah with other party.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  &gt;Enter pjsip4net: &lt;a href="http://code.google.com/p/pjsip4net/"&gt;http://code.google.com/p/pjsip4net/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Good luck!&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-48009709978359465?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=3tlJvLKqoxw:pBIiR_znZlA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=3tlJvLKqoxw:pBIiR_znZlA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/3tlJvLKqoxw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/3tlJvLKqoxw/my-two-cents-in-oss-free-voip-net.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>1</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2010/08/my-two-cents-in-oss-free-voip-net.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-5641763679712983583</guid><pubDate>Sat, 02 Jan 2010 11:13:00 +0000</pubDate><atom:updated>2010-01-14T01:42:19.345-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">sql</category><category domain="http://www.blogger.com/atom/ns#">nhibernate</category><title>ORM-style Identity generator or impossible is nothing.</title><description>&lt;span style=";font-family:verdana;font-size:85%;"  &gt;What the hell?! Isn't it a bit like even odds? &lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Everybody knows that it is impossible to prevent NHibernate from breaking Unit of Work semantics, when your primary keys are generated by SQL Server Identity facility. To justify that, please read the following: &lt;/span&gt;&lt;a href="http://devlicio.us/blogs/tuna_toksoz/archive/2009/03/20/nhibernate-poid-generators-revealed.aspx"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;generators revealed&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;, and follow on with &lt;/span&gt;&lt;a href="http://fabiomaulo.blogspot.com/2008/12/identity-never-ending-story.html"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;this story&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;In short, the major problem of Identity generator is that it is a post insert generator, that is to say it can't produce new Id value without INSERT statement being executed by database engine. Furthermore NHibernate can't persist entity &lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;without Id. That is why NHibernate will insert our object to the database the moment it was persisted without waiting for Flush() to be called. This causes huge problems should you try to implement long-running business transactions. The biggest trouble is that you won't be able to rollback changes made in business transaction.&lt;br /&gt;&lt;br /&gt;In short, this is what I want to achieve: &lt;/span&gt;&lt;br /&gt;&lt;ul  style="font-family:verdana;"&gt;&lt;li&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;insert values into Identity fields on my own;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;acqiure correct Identity values that wouldn't cause troubles in database; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;UPD:&lt;/span&gt; As it was fairly noticed, it looks like I work very hard to get something that is already in the box (HiLo). It really looks like that, but I have to prove that is not a waste of time. The point is that my case is constrained with existing database with defined schema. This database is filled with loads of records by other processes that I have no access to. That is why I can't use solutions like HiLo and have to invent my own.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;In SQL Server one can disable autoincrement for Identity field and &lt;/span&gt;&lt;a href="http://mysoftskill.blogspot.com/2009/11/cannot-insert-explicit-value-for.html"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;insert its own values&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;. But how would he get a correct value? The easiest way is to insert a dummy row in a local transaction and then perform a rollback. After transaction was cancelled, &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms190315.aspx"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Identity&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt; value won't be reverted. Thus, by changing a table and reverting all changes made, we produce a gap in an Identity sequence, and the gap value can be inserted manually afterwards.&lt;br /&gt;&lt;br /&gt;Having said that, I've drawn a following sequence diagram:&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="font-family: verdana;" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SzSWllrpopI/AAAAAAAAMBo/aIAbOjWF0Zg/s1600-h/ORMIdGenFlow.png"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;img id="BLOGGER_PHOTO_ID_5419121824148071058" style="width: 400px; cursor: pointer; height: 206px;" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SzSWllrpopI/AAAAAAAAMBo/aIAbOjWF0Zg/s400/ORMIdGenFlow.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;The solution, as it comes from a diagram above, consists of 3 parts: &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul face="verdana"&gt;&lt;li&gt;&lt;a href="http://nhforge.org/wikis/howtonh/creating-a-custom-id-generator-for-nhibernate.aspx"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Custom Id generator&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;, which I've called ORMIdentityGenerator;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;PreInsert listener, to disable Identity field autoincrement;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;PostInsert listener, to enable Identity field autoincrement back;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;font-size:85%;"  &gt;ORMIdentityGenerator&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="font-family: verdana;" href="http://1.bp.blogspot.com/_aPBCtYeet9E/SzTeNAjKYUI/AAAAAAAAMBw/SktSuv0WGNc/s1600-h/ORMIdGen.png"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;img id="BLOGGER_PHOTO_ID_5419200566700695874" style="width: 400px; cursor: pointer; height: 249px;" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/SzTeNAjKYUI/AAAAAAAAMBw/SktSuv0WGNc/s400/ORMIdGen.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;This is an easiest possible implementation of what I was talking before. Agile principles say KISS - &lt;b style="font-family: verdana;"&gt;keep it simple, stupid!&lt;/b&gt; and that is what I do. This generator is merely an INSERT statement executor. One can configure it with the INSERT statement to perform safe (in terms of database integrity) operation that will change a table and force database to produce a new Identity value. This value will be returned with a next SELECT statement execution&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;"&gt;PreInsert&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="font-family: verdana;" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SzTeNZrmYuI/AAAAAAAAMB4/Ksm_BUTovCY/s1600-h/PreInsert.png"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;img id="BLOGGER_PHOTO_ID_5419200573446972130" style="width: 400px; cursor: pointer; height: 241px;" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SzTeNZrmYuI/AAAAAAAAMB4/Ksm_BUTovCY/s400/PreInsert.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;font-size:85%;"  &gt;PostInsert&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="font-family: verdana;" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SzTeNi7RAPI/AAAAAAAAMCA/5rxVplBtj34/s1600-h/PostInsert.png"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;img id="BLOGGER_PHOTO_ID_5419200575928598770" style="width: 400px; cursor: pointer; height: 226px;" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SzTeNi7RAPI/AAAAAAAAMCA/5rxVplBtj34/s400/PostInsert.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;That's it. Now I can edit my persistent objects with Id field generated by Identity in &lt;/span&gt;&lt;a href="http://fabiomaulo.blogspot.com/2008/12/conversation-per-business-transaction.html"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;a long-running session&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt; and rollback changes should I need it. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Good luck! &lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-5641763679712983583?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=cjpWDZboqjQ:Tmwkxzc2s5A:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?a=cjpWDZboqjQ:Tmwkxzc2s5A:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/blogspot/robbbloggg?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/cjpWDZboqjQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/cjpWDZboqjQ/orm-style-identity-generator-or.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_aPBCtYeet9E/SzSWllrpopI/AAAAAAAAMBo/aIAbOjWF0Zg/s72-c/ORMIdGenFlow.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2010/01/orm-style-identity-generator-or.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-1186654996209528156</guid><pubDate>Thu, 28 Aug 2008 12:03:00 +0000</pubDate><atom:updated>2010-01-10T12:24:56.091-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">IoC</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CAB</category><title>Dependency Injection in xaml</title><description>&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;I want to describe a solution I've found to &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;a href="http://martinfowler.com/articles/injection.html"&gt;inject dependencies&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; of my objects right in Xaml. &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;This solution is special because it is coupled with &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;a href="http://www.blogger.com/msdn.microsoft.com/en-us/library/aa480450.aspx"&gt;CAB&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;that&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; I use as a platform for my smartclient applications, but I sincerely hope that you will see the idea behind particular implementation that will let you abstract this solution away from particular IoC&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; framework. &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Quite often I create objects in Xaml, and I'd like to follow the main principles of my development. As a part of this I'd like to inject dependencies in objects, being created by WPF, like I &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;do it in code-behind.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-size:85%;" &gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="FONT-FAMILY: verdana" href="http://1.bp.blogspot.com/_aPBCtYeet9E/SLatrIwwJbI/AAAAAAAAE7k/fneWot27-dw/s1600-h/DIEx1.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5239566173090096562" style="CURSOR: pointer" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/SLatrIwwJbI/AAAAAAAAE7k/fneWot27-dw/s400/DIEx1.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;So I need a solution that will&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; fit following&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; requirements:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul style="COLOR: rgb(0,0,0);font-family:verdana;" &gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;ability to be used in Binding;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;ability to be used with POCO.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;My solution consists of the same &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;number of parts &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;as abovementioned requirements&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;:&lt;/span&gt; &lt;ul style="COLOR: rgb(0,0,0);font-family:verdana;" &gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;IoCProvider - custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.datasourceprovider.aspx"&gt;DataSourceProvider&lt;/a&gt; (Binding "knows" &lt;/span&gt;&lt;span style="font-size:85%;"&gt;about DataSourceProvider and works &lt;/span&gt;&lt;span style="font-size:85%;"&gt;with it &lt;/span&gt;&lt;span style="font-size:85%;"&gt;perfectly);&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;a set of MarkupExtensions to be used with POCO;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: rgb(0,0,0)font-family:verdana;font-size:85%;"  &gt;IoCProvider&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;IoCProvider is the core of my solution. It is the part that infers dependencies by means of standard CAB IoC container - WorkItem.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_aPBCtYeet9E/SLahyHS-UmI/AAAAAAAAE7M/vXLL5HnHx_o/s1600-h/DIProvider.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5239553098816311906" style="CURSOR: pointer" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SLahyHS-UmI/AAAAAAAAE7M/vXLL5HnHx_o/s400/DIProvider.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Since&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; this object &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;is created &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;mostly&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;by &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;WPF engine, there is no way to inject a container into IoCProvider, but here &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;we can use a well-known &lt;a href="http://martinfowler.com/eaaCatalog/registry.html"&gt;registry&lt;/a&gt; object, such as an Application object in WPF. Considering that my Application always implements IRootApplication interface, that is bound to publish root WorkItem, this task is no more a matter of interest (see IoCProvider constructor).&lt;br /&gt;&lt;br /&gt;Main job in inferring of dependencies is done in BeginQuery method. One can initiate a query by calling a base &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;DataSourceProvider&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt; class Refresh() method manually, or it will be done automatically by means of Binding system.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_aPBCtYeet9E/SLahyfYrfjI/AAAAAAAAE7U/SksOEXy7QFY/s1600-h/DIQuery.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5239553105282694706" style="CURSOR: pointer" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/SLahyfYrfjI/AAAAAAAAE7U/SksOEXy7QFY/s400/DIQuery.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Now we can use this provider as a source of data in Binding, but &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;attempts&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;to bind POCO's property or field to requested dependency will cause an InvalidOperationException to be thrown, informing us that binding can be used only with Dependency Property. How do we escape this?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: rgb(0,0,0)font-family:verdana;font-size:85%;"  &gt;Markup Extension.&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;This is the solution for the second part - markup extension. Markup extensions can be used &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;almost&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;everywhere in xaml. &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;ServiceDependencyMarkupExtension is my example implementation, which infers WorkItem's service &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;dependencies&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;.&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_aPBCtYeet9E/SLahycvpGVI/AAAAAAAAE7c/p0udg1O74WA/s1600-h/DIServExt.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5239553104573700434" style="CURSOR: pointer" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SLahycvpGVI/AAAAAAAAE7c/p0udg1O74WA/s400/DIServExt.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Below follows the result - we &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt;inject&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:Verdana;font-size:85%;"  &gt; &lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;our dependencies right in Xaml! Isn't it awesome?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-size:85%;" &gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="FONT-FAMILY: verdana" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SLauOHPdczI/AAAAAAAAE7s/b4hBNSnwZIA/s1600-h/DIEx2.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5239566773977445170" style="CURSOR: pointer" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SLauOHPdczI/AAAAAAAAE7s/b4hBNSnwZIA/s400/DIEx2.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;I hope now you see how simple the dependency injection in xaml is, and I also hope you'd be able to make a step further and abstract the whole solution away from concrete IoC framework. You can see an example of such solution in &lt;a href="http://www.blogger.com/www.codeplex.com/CompositeWPF"&gt;Prism&lt;/a&gt; - its IContainerFacade interface.&lt;br /&gt;&lt;br /&gt;Here is a couple of articles that will help you in process:&lt;br /&gt;&lt;a href="http://joshsmithonwpf.wordpress.com/2007/06/19/creating-a-custom-datasourceprovider/"&gt;creating-a-custom-datasourceprovider&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;a href="http://dvuyka.spaces.live.com/blog/cns%21305B02907E9BE19A%21307.entry"&gt;Injecting Xaml&lt;/a&gt; &lt;a href="http://dvuyka.spaces.live.com/blog/cns%21305B02907E9BE19A%21313.entry"&gt;with Unity&lt;/a&gt; &lt;a href="http://dvuyka.spaces.live.com/blog/cns%21305B02907E9BE19A%21321.entry"&gt;Application Block&lt;/a&gt; &lt;a href="http://dvuyka.spaces.live.com/blog/cns%21305B02907E9BE19A%21331.entry"&gt;using Markup Extensions&lt;/a&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,0);font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Good luck! &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-1186654996209528156?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=6LUkGx8S"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=wOJWo32t"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/AAvG_3jYj4s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/AAvG_3jYj4s/dependency-injection-in-xaml.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_aPBCtYeet9E/SLatrIwwJbI/AAAAAAAAE7k/fneWot27-dw/s72-c/DIEx1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/08/dependency-injection-in-xaml.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-1462997177760911022</guid><pubDate>Wed, 06 Aug 2008 12:47:00 +0000</pubDate><atom:updated>2008-08-06T23:30:41.386-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><title>Kodama - a spirit of tree.</title><description>&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;Some of you have probably read my post about Josh Smith and ViewModel coming to rescue people (WPF-addicted people, to be precise), just joking don't mind. In brief words, I wrote how ViewModel helped working with ComboBox or another Selector control to manage state of underlying CollectionView. After that I've generalized my thoughts, and there came a SelectorCollectionPresenter class, which made my sleep quiet. =) I'll publish code in the end as a bonus.&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;But now I want to write about the TreeView control, and how it can be united and simplified with ViewModel pattern. I was inspired a long time ago, when I read &lt;/span&gt;&lt;span style=""&gt;&lt;a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx"&gt;&lt;span  lang="EN-US" style="font-family:Verdana;"&gt;this&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt; article by Josh Smith, but had no time to work with WPF, solving other infrastructural problems, but I've got the idea stuck in my head.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div  style="text-align: left;font-family:verdana;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;And finally I got time to think about it and put it together in a reusable manner. As a result I've got a tree control with a spirit living in it. I named it &lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;a href="http://en.wikipedia.org/wiki/Kodama_%28spirit%29"&gt;&lt;span style="" lang="EN-US"&gt;Kodama&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;, because kodama is a spirit from Japanese folklore, which is believed to live in trees. And the control itself was called KodamaView. As you might have already guessed, this spirit, which lives in my tree control, is nothing more than a ViewModel!&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_aPBCtYeet9E/SJMMzoxquDI/AAAAAAAAE1I/Ho4h_-AJ64w/s1600-h/800px-Mononoke_Kodama.jpg"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5229537673565878322" style="cursor: pointer;" alt="" src="http://bp1.blogger.com/_aPBCtYeet9E/SJMMzoxquDI/AAAAAAAAE1I/Ho4h_-AJ64w/s400/800px-Mononoke_Kodama.jpg" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;- he said ViewModel?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;I want to warn everybody – I've just put together my thoughts on DM-V-VM pattern and Josh's fantastic ideas, so most of honors should go right to Josh!&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;KodamaView&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;KodamaView - is a UserControl, hosting a TreeView inside itself. In order to simulate TreeView's behavior, it inherits ITreeView interface, based on my &lt;/span&gt;&lt;span style=""&gt;&lt;a href="http://bobbbloggg.blogspot.com/2008/02/model-view-viewmodel-framework.html"&gt;&lt;span  lang="EN-US" style="font-family:Verdana;"&gt;IWPFView&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt; interface, and delegates all incoming calls to internal TreeView control.&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/SJmriop70FI/AAAAAAAAE2o/HaTAvgpg8Y4/s1600-h/ITreeView1.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231401053684748370" style="" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/SJmriop70FI/AAAAAAAAE2o/HaTAvgpg8Y4/s400/ITreeView1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;TreeView simulating interface.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/SJmri4Ot0gI/AAAAAAAAE2w/ZedK6a0eDLc/s1600-h/KodamaView1.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231401057865552386" style="" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SJmri4Ot0gI/AAAAAAAAE2w/ZedK6a0eDLc/s400/KodamaView1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;KodamaView control.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_aPBCtYeet9E/SJMRXKsordI/AAAAAAAAE1g/JfgPG3awN-Y/s1600-h/KodamaViewxaml.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5229542682013511122" style="cursor: pointer;" alt="" src="http://bp1.blogger.com/_aPBCtYeet9E/SJMRXKsordI/AAAAAAAAE1g/JfgPG3awN-Y/s400/KodamaViewxaml.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;Control's xaml.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;span style="font-weight: bold;"&gt;Kodama.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;And now here are some words about Kodama.&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_aPBCtYeet9E/SJMMyAc-v9I/AAAAAAAAE1A/MkA_6m2ebpI/s1600-h/SekienKodama.jpg"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5229537645561823186" style="cursor: pointer;" alt="" src="http://bp3.blogger.com/_aPBCtYeet9E/SJMMyAc-v9I/AAAAAAAAE1A/MkA_6m2ebpI/s400/SekienKodama.jpg" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a title="Toriyama Sekien" href="http://en.wikipedia.org/wiki/Toriyama_Sekien"&gt;&lt;span style="font-family:verdana;"&gt;Toriyama Sekien&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;"&gt;'s illustration of a &lt;i&gt;kodama&lt;/i&gt; appearing as an old man.&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;My Kodama (if it is allowed to say so) is an inheritor of &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-2.html"&gt;&lt;span  lang="EN-US" style="font-family:Verdana;"&gt;ViewModel&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt; class, parameterized with ITreeView and &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-1.html"&gt;&lt;span  lang="EN-US" style="font-family:Verdana;"&gt;IDataModelBase&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt; interfaces. The last one is made basic to be able to create Kodama with any &lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;derived&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt; DataModel class, because all of them embody this interface. DM is the source of data for the tree.&lt;/span&gt;&lt;span lang="EN-US"  style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/SJmrzMQMHTI/AAAAAAAAE24/P7gPCYOd4x8/s1600-h/Kodama1.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231401338118348082" style="" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SJmrzMQMHTI/AAAAAAAAE24/P7gPCYOd4x8/s400/Kodama1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="text-align: left;font-family:verdana;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Every TreeViewItem gets its own ViewModel - a TreeViewItemViewModel.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SJmr-rBMhOI/AAAAAAAAE3A/DZB1gabix4c/s1600-h/TVIVM.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231401535355520226" style="" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SJmr-rBMhOI/AAAAAAAAE3A/DZB1gabix4c/s400/TVIVM.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;TreeView is able to load child nodes "lazily", only when their parent node is expanded (I've borrowed the code from Josh's article, I hope he doesn't mind). All work on loading children is done in a LoadChildren method.&lt;/span&gt;&lt;div  style="text-align: left;font-family:verdana;"&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SJmsY5_r1hI/AAAAAAAAE3I/h0uva8_sAn0/s1600-h/Kodama2.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231401986052314642" style="" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SJmsY5_r1hI/AAAAAAAAE3I/h0uva8_sAn0/s400/Kodama2.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;There is another one class in hierarchy - TreeViewItemViewModel`1. It has only one purpose to exist - to populate a typed Entity into the visual tree.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/SJmsnCd_ftI/AAAAAAAAE3Q/aiQzMdtTHDM/s1600-h/TVIVM%60.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231402228845084370" style="" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SJmsnCd_ftI/AAAAAAAAE3Q/aiQzMdtTHDM/s400/TVIVM%60.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;StructureTreeKodama is my example demonstrating this philosophy.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SJqWIqzH2CI/AAAAAAAAE3o/C8UoyjUMjc4/s1600-h/StructKodama3.png"&gt;&lt;img style="cursor: pointer;" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SJqWIqzH2CI/AAAAAAAAE3o/C8UoyjUMjc4/s400/StructKodama3.png" alt="" id="BLOGGER_PHOTO_ID_5231658992816085026" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/SJmvLAyD6OI/AAAAAAAAE3g/POSgX0C2CMM/s1600-h/StructKodama2.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5231405045890935010" style="" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SJmvLAyD6OI/AAAAAAAAE3g/POSgX0C2CMM/s400/StructKodama2.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="text-align: left;font-family:verdana;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;I remember, when I started the post, I've promised you a bonus. So here it is - SelectorCollectionPresenter class code. You can read some on details of it &lt;/span&gt;&lt;span style=";font-size:85%;" &gt;&lt;a href="http://robbbloggg.blogspot.com/2008/06/how-josh-saved-my-day-or-power-of-model.html"&gt;&lt;span  lang="EN-US" style="font-family:Verdana;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  lang="EN-US" &gt;.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_aPBCtYeet9E/SJMYheOqXRI/AAAAAAAAE2I/o349x3sAHwI/s1600-h/SelectorPresenter.png"&gt;&lt;span style="font-family:verdana;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5229550555636587794" style="cursor: pointer;" alt="" src="http://bp0.blogger.com/_aPBCtYeet9E/SJMYheOqXRI/AAAAAAAAE2I/o349x3sAHwI/s400/SelectorPresenter.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;Good luck! &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-1462997177760911022?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=PIR4X9JL"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=DW5eBPjF"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/noC2D8sPpAc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/noC2D8sPpAc/kodama-spirit-of-tree.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://bp1.blogger.com/_aPBCtYeet9E/SJMMzoxquDI/AAAAAAAAE1I/Ho4h_-AJ64w/s72-c/800px-Mononoke_Kodama.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/08/kodama-spirit-of-tree.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-6013201450536408187</guid><pubDate>Tue, 24 Jun 2008 11:06:00 +0000</pubDate><atom:updated>2008-06-24T04:16:35.712-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><category domain="http://www.blogger.com/atom/ns#">wizard</category><title>WPF Presentation layer</title><description>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: verdana;"&gt;I am about to stop blogging for next three weeks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;I'd like you to spend this time with pleasure and use so here is the candy: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.megaupload.com/ru/?d=OEWPQ15D"&gt;Presentation Layer&lt;/a&gt;&lt;span style="font-family: verdana;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;This is a small framework to help develop desktop WPF applications. Mostly it is a &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://robbbloggg.blogspot.com/search/label/DM-V-VM"&gt;DM-V-VM&lt;/a&gt; implementation with some other stuff I've blogged about.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;And, finally, I am going to make a candy more yummy. I've included source codes for my WPF Wizard control as I've promissed some time ago.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Enjoy!&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-6013201450536408187?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=TJFEutux"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=wd0pFwXl"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/D19R8SLsicM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/D19R8SLsicM/wpf-presentation-layer.html</link><author>noreply@blogger.com (RobertT)</author><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/06/wpf-presentation-layer.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-7816468038479906970</guid><pubDate>Fri, 06 Jun 2008 13:15:00 +0000</pubDate><atom:updated>2008-06-10T23:24:27.763-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><title>How Josh saved my day or the power of the Model side</title><description>&lt;span style="font-family: verdana;font-size:85%;" id="rzdz0" &gt;&lt;span id="rzdz1"&gt;&lt;span id="rzdz2"  style="color:#333333;"&gt;&lt;span id="rzdz3" lang="en-US"&gt;May be I&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt; miss&lt;/span&gt;&lt;span style="font-family: verdana;font-size:85%;" id="rzdz0" &gt;&lt;span id="rzdz1"&gt;&lt;span id="rzdz2"  style="color:#333333;"&gt;&lt;span id="rzdz3" lang="en-US"&gt;ed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt; something but it was a challenge for me to maintain a following situation.&lt;/span&gt; &lt;div style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-size:85%;"&gt;Imagine, for example, that you have an object with some property that can be chosen from some&lt;/span&gt;&lt;span style="font-size:85%;"&gt; external list of values. How would you solve it? You'll, probably, put in UI some Selector control, say it &lt;/span&gt;&lt;span id="rzdz12"  style="font-size:85%;"&gt;&lt;span id="rzdz13"&gt;&lt;span id="rzdz14"  style="color:#333333;"&gt;&lt;span id="rzdz15" lang="en-US"&gt;would&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; be a ComboBox, bound with list of available values. You would bind &lt;/span&gt;&lt;span id="rzdz12"  style="font-size:85%;"&gt;&lt;span id="rzdz13"&gt;&lt;span id="rzdz14"  style="color:#333333;"&gt;&lt;span id="rzdz20" lang="en-US"&gt;its&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; SelectedItem property with underlying object's target property by means of OneWayToSource binding. Quite easy so far, isn't it? Just write ViewModel for this view that will publish this object and will keep all logic. Now let's make this example a little trickier. Imagine that you have to edit a list of said objects and you have to choose a unique value for every particular object. You see now that it is not so easy anymore? And to puzzle you completely picture yourself a Configuration Dialog that hosts your editing UI. This dialog has OK and cancel button and your objects' state must stay sync with what you do. Something like the following:&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_aPBCtYeet9E/SE5WzdBuKqI/AAAAAAAAExI/AWcwMirrpco/s1600-h/addinsdialog.png"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SE5WzdBuKqI/AAAAAAAAExI/AWcwMirrpco/s400/addinsdialog.png" alt="" id="BLOGGER_PHOTO_ID_5210197260879407778" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;Don't be scared this UI is just for tests =).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I've written a number of posts about &lt;a href="http://robbbloggg.blogspot.com/search/label/DM-V-VM"&gt;M-V-VM&lt;/a&gt; pattern, but in spite of was completely cumbered with this scenario. I do have an infrastructure to edit objects (I've written about it &lt;a href="http://bobbbloggg.blogspot.com/2008/03/configurationdialog.html"&gt;here&lt;/a&gt;), but in this case I was baffled. The problem was with this list of available values. To make it easier for understanding I'll introduce some classes. &lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-size:85%;"&gt;The scenario is as follows: I have a number of visual addins (powered by &lt;a href="http://www.codeplex.com/clraddins"&gt;Managed Add-Ins Framework&lt;/a&gt;) (I really should write about it, but I'll do it later) that I want to host in my UI. But they can be hosted only in the named Workspaces (a &lt;a href="http://msdn.microsoft.com/en-us/library/aa480450.aspx"&gt;CAB&lt;/a&gt;'s notion, it is not a WPF restriction it is my &lt;/span&gt;&lt;span id="rzdz85"  style="font-size:85%;"&gt;&lt;span id="rzdz86"&gt;&lt;span id="rzdz87"  style="color:#333333;"&gt;&lt;span id="rzdz88" lang="en-US"&gt;decision&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;). You can see the model now. I've got AddInDescriptor objects that keep a name of containing workspace and addin token. This name can be set in Configuration Dialog by browsing and selecting one from available list. This dialog can commit or rollback changes and &lt;/span&gt;&lt;span id="rzdz85"  style="font-size:85%;"&gt;&lt;span id="rzdz86"&gt;&lt;span id="rzdz87"  style="color:#333333;"&gt;&lt;span id="rzdz98" lang="en-US"&gt;at next start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; it must show appropriate content.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_aPBCtYeet9E/SE49QG-f1mI/AAAAAAAAEwY/vWvNbX6yETc/s1600-h/addindesc.png"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SE49QG-f1mI/AAAAAAAAEwY/vWvNbX6yETc/s400/addindesc.png" alt="" id="BLOGGER_PHOTO_ID_5210169165874189922" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;descriptor class. just a DTO.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_aPBCtYeet9E/SE4_fLynhUI/AAAAAAAAEwo/2ItotRFCEd8/s1600-h/addintempl.png"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SE4_fLynhUI/AAAAAAAAEwo/2ItotRFCEd8/s400/addintempl.png" alt="" id="BLOGGER_PHOTO_ID_5210171623887832386" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;descriptor data template.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_aPBCtYeet9E/SE4_fR58K0I/AAAAAAAAEww/jr9sUrtkxJI/s1600-h/addindesclistboxitem.png"&gt;&lt;img style="cursor: pointer;" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SE4_fR58K0I/AAAAAAAAEww/jr9sUrtkxJI/s400/addindesclistboxitem.png" alt="" id="BLOGGER_PHOTO_ID_5210171625529158466" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;listbox item style.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The problem &lt;/span&gt;&lt;span id="rzdz104" lang="en-US"&gt;&lt;span id="rzdz105"  style="font-size:85%;"&gt;&lt;span id="rzdz106"&gt;&lt;span id="rzdz107"  style="color:#333333;"&gt;looks like this:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; when I first set the name of containing workspace and then rollback and start again, combobox updates current item binding (AddInDescriptor.ContainingWorkspaceName property) with a valid empty workspace name and then explicitly sets the first item as current without update. This strange behavior violates all the logic written in a style's triggers. I tried to fix this broken behavior in a whole bunch of ways but neither of them worked.&lt;br /&gt;&lt;br /&gt;And this is whe&lt;/span&gt;&lt;span id="rzdz104" lang="en-US"&gt;&lt;span id="rzdz105"  style="font-size:85%;"&gt;&lt;span id="rzdz106"&gt;&lt;span id="rzdz107"  style="color:#333333;"&gt;n an idea dawned at&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; me! I remembered a beautiful article written by WPF-&lt;/span&gt;&lt;span id="rzdz104" lang="en-US"&gt;&lt;span id="rzdz105"  style="font-size:85%;"&gt;&lt;span id="rzdz106"&gt;&lt;span id="rzdz107"  style="color:#333333;"&gt;rock star&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (of course it was Josh, who else?) about the simplest way to manage a TreeView in WPF. Here it is: &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx" class="m" target="_blank"&gt;http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx&lt;/a&gt;. &lt;/span&gt;&lt;span id="rzdz124" lang="en-US"&gt;&lt;span id="rzdz125"  style="font-size:85%;"&gt;&lt;span id="rzdz126"&gt;&lt;span id="rzdz127"  style="color:#333333;"&gt;I say this article is a &lt;b id="rzdz128"&gt;MUST &lt;/b&gt;read.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;And then I thought: "What is the difference? I have to do the same with ComboBox in my case.",  and everything became clear.&lt;br /&gt;&lt;br /&gt;I've created a AddInDescriptorPresenter class that held all the UI related logic. It is nothing more then a UI-proxy to the object and is intended to publish object- and UI-related properties. This class accepts a CollectionView (a built-in VM for collection) which a Combo is bound with.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_aPBCtYeet9E/SE49QRdpLdI/AAAAAAAAEwg/2iPgxV--Ztg/s1600-h/addindescpresenter.png"&gt;&lt;img style="cursor: pointer;" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SE49QRdpLdI/AAAAAAAAEwg/2iPgxV--Ztg/s400/addindescpresenter.png" alt="" id="BLOGGER_PHOTO_ID_5210169168689180114" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;AddIn descriptor presenter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A list of these proxies is created and exposed by UI ViewModel that keeps a list of AddInDescriptors.&lt;br /&gt;&lt;br /&gt;You might be interested what the TransactionalTune is. &lt;/span&gt;&lt;span id="rzdz138" lang="en-US"&gt;&lt;span id="rzdz139"  style="font-size:85%;"&gt;&lt;span id="rzdz140"&gt;&lt;span id="rzdz141"  style="color:#333333;"&gt;TransactionalTune&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; is a special data container, a volatile transaction manager based on Juval Lowy's fantastic &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163688.aspx"&gt;article.&lt;/a&gt; &lt;/span&gt;&lt;span id="rzdz153" lang="en-US"&gt;&lt;span id="rzdz154"  style="font-size:85%;"&gt;&lt;span id="rzdz155"&gt;&lt;span id="rzdz156"  style="color:#333333;"&gt;You can read more&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;a href="http://bobbbloggg.blogspot.com/2008/03/configurationdialog.html"&gt;here&lt;/a&gt;.&lt;br /&gt;All this UI-proxy does is controlling the state of CollectionView that is synchronized with ComboBox.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_aPBCtYeet9E/SE5IYZyCQyI/AAAAAAAAEw4/ECYyFDqA2xo/s1600-h/addindescpresentercode.png"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SE5IYZyCQyI/AAAAAAAAEw4/ECYyFDqA2xo/s400/addindescpresentercode.png" alt="" id="BLOGGER_PHOTO_ID_5210181402989052706" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;AddInDescriptorPresenter code.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Template to render this presenter became a little bit easier.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_aPBCtYeet9E/SE5IY1y3jfI/AAAAAAAAExA/5N06QtBhU6g/s1600-h/addindescpresentertempl.png"&gt;&lt;img style="cursor: pointer;" src="http://3.bp.blogspot.com/_aPBCtYeet9E/SE5IY1y3jfI/AAAAAAAAExA/5N06QtBhU6g/s400/addindescpresentertempl.png" alt="" id="BLOGGER_PHOTO_ID_5210181410508738034" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;AddInDescriptorPresenter data template.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I've spent a couple of days trying to solve this problem writing tons of different xamls and code-behinds, and it took me about an hour to make everything work correctly with the ViewModel!&lt;br /&gt;You see now that it is powerful?&lt;br /&gt;&lt;br /&gt;Good luck!&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-7816468038479906970?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=MJcAFrHs"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=JOSe11rJ"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/lw7Gjj8zSF8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/lw7Gjj8zSF8/how-josh-saved-my-day-or-power-of-model.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_aPBCtYeet9E/SE5WzdBuKqI/AAAAAAAAExI/AWcwMirrpco/s72-c/addinsdialog.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/06/how-josh-saved-my-day-or-power-of-model.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-2955130620840225924</guid><pubDate>Fri, 30 May 2008 18:31:00 +0000</pubDate><atom:updated>2008-06-02T05:16:54.089-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">patterns</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">wizard</category><title>Business Objects validation in WPF wizard</title><description>&lt;span style="font-family:verdana;font-size:85%;"&gt;Oh dear! Is it really me writing? Well, yeah, it is me! &lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I had a lot of fun in Mediterranean yachting and now I am full of strength to manage with my thoughts' flow. =)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;While writing this post I understood that I chose the very interesting theme to my mind - WPF wizard component development that I've done for my projects. But then I realized that it would take a year to highlight all the process with my speed of posting, so I came back to the original title and focused on the particular theme. I'll try to write on WPF wizard later on, but to keep your interested I'm going to include wizard's sources.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;As I've mentioned in my &lt;/span&gt;&lt;a href="http://robbbloggg.blogspot.com/search/label/DM-V-VM"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;previuos posts on DM-V-VM pattern &lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I don't edit objects in most of UIs. The reason is simple - ViewModel doesn't track edited object state. I do it in wizards. WPF doesn't contain such a useful component as a wizard by default so you have 2 ways out: &lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;1st - pay someone for ready custom component and the 2nd one - write your own. I chose 2nd one =) as I often did. It was a very big work that brought tons of difficulties and challenges but was a lot of fun to solve. Propably the biggest challenge was UI integration in validation process where UI could track underlying objects' state and react respectively avoiding user from saving objects in an inconsistent state. I knew about validation in WPF binding, but it was not quite the thing I needed. (In WPF that goes with .Net 3.5 business objects validation can be plugged in validation process easily by using ValidatesOnError binding property and IDataErrorInfo interface in object, but still it is not quite one I needed). Karl Shifflet wrote a wonderful article on validation and WPF business applications developement generally, here it is: &lt;/span&gt;&lt;a href="http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; .&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;As an alternative to editing objects in wizard you can use &lt;/span&gt;&lt;a href="http://www.acceptedeclectic.com/2008/01/model-view-viewmodel-pattern-for-wpf.html"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;this&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; approach, which I've mentioned earlier.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;So what do I need and what do I want?&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I want: &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;UI to track underlying objects' state automatically and react respectively - buttons Next, Save should be disabled in case an underlying object is in invalid state; in other words wizard should not let you make a mistake;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;developer writing wizard code to avoid taking part in validation process, in other words validation must start automatically in a transparent way, no code-behind with validation code; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I have:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;V&lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms753962.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;alidation in WPF binding engine&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; already exists. One can plug in by writing his own ValidationRule descendant. There also is a static class Validation that provide means to set ErrorTemplate for UI control and get errors collection. So why doesn't it fit our needs? The reason is simple - it validates the UI data - not underlying objects, but we need a unified process that will validate business objects decoupled from UI technology. Therefore we won't use WPF validation as a main engine, but only as an extensibility point;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb410105.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Validation Application Block&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; (VAB), that was developed to validate objects, can be found in &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/ru-ru/library/aa480453(en-us).aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Enterprise library&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; (EL);&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;There is command notion in WPF that can control UI state. I &lt;/span&gt;&lt;a href="http://robbbloggg.blogspot.com/2008/04/wpf-command-cab-command-run-into-one.html"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;wrote&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; about'em in previous posts.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Well, it seems that we have all we need! So let's go on.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;First of all let's check out this scenario: we've got a wizard that edits a human/visitor (whatever) entity.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;you fill in first name, last name and other fields at wizard's first page, and the first name field is mandatory.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;you provide an entity with the access data such as login, password and password confirmation in the second page;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;you fill all the blahblahblah fields in the rest of a wizard's pages... =)&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/SD6z99ldkXI/AAAAAAAAEu4/kLqulzY8gG4/s1600-h/wizard1.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205796096371954034" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/SD6z99ldkXI/AAAAAAAAEu4/kLqulzY8gG4/s400/wizard1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;Entity you edit in my wizard is applied to DataContext property, thus enabling all the visual tree (pages with controls in it) to inherit the last one.&lt;br /&gt;&lt;br /&gt;Every UI control, which triggers some action, is bounded with a command. Every command is wrapped in alreasy &lt;/span&gt;&lt;a href="http://bobbbloggg.blogspot.com/2008/02/model-view-viewmodel-framework.html"&gt;&lt;span style="font-size:85%;"&gt;familiar&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;a href="http://blogs.msdn.com/dancre/archive/2006/09/15/dm-v-vm-part-7-encapsulating-commands.aspx"&gt;&lt;span style="font-size:85%;"&gt;CommandModel&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; class. Said models are holding command's state and execution logic. And what I intend to do is to delegate them validation.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;First I used to delegate validation logic to my domain objects (you can read about this approach &lt;/span&gt;&lt;a href="http://bobbbloggg.blogspot.com/2008/03/business-objects-validation-and-ui.html"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;) but it made my wizard control tightly coupled with my domain model, which is ugly! So I've changed a direction and made my commands validating edited entities. I use Validation Application Block from Enterprise Library. David Hayden has a tons of tutorials on p'n'p's products, including &lt;/span&gt;&lt;a href="http://davidhayden.com/blog/dave/archive/2006/12/28/ValidationApplicationBlockBusinessLayerDataAccessLayerIntegration.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;this&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; &lt;/span&gt;&lt;a href="http://davidhayden.com/blog/dave/archive/2006/12/23/ValidationApplicationBlockEnterpriseLibrary3PartI.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;set&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; &lt;/span&gt;&lt;a href="http://davidhayden.com/blog/dave/archive/2006/12/24/ValidationApplicationBlockEnterpriseLibrary3PartII.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;of&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; &lt;/span&gt;&lt;a href="http://davidhayden.com/blog/dave/archive/2006/12/25/ValidationApplicationBlockEnterpriseLibrary3PartIII.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;articles&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; on VAB, so I won't write on how VAB is working because you can read everything there. &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Wizard edit process is divided into pages that holds some logical associated data, and this logical association correlates with ValidationRuleSet notion, so every WizardPage carries a RuleSet property, that must be set on developement stage. &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;When it comes to validation I simply call VAB's facade to do the work.&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Here is what our visitor class might look like:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/SD6z9tldkWI/AAAAAAAAEuw/9FsFwZQIu7k/s1600-h/VisitorExpl.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205796092076986722" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/SD6z9tldkWI/AAAAAAAAEuw/9FsFwZQIu7k/s400/VisitorExpl.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;You see it has a property Name that is marked with StringLengthValidator attribute [1;200) with the CommanRuleSet ruleset name, and wizard page that edit this property must have the same ruleset name.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Now, when we finished with validation we can start writing our commands logic.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I have the following commands in wizard: &lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;NextPage - a command that transfers you to the next page;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;PrevPage - a command that transfers you to the previous page;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;GoToPage - a command that performs a gap to the specified number of pages;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Save - a command that triggers Finish event;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Cancel - a command that triggers Cancel event;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Help - a command that shows a user manual;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I'll make an example with the NextPage Command. Command checks whether an entity is valid with corresponding ruleSet, and whether the current page is not last and whether this page is not marked as invalid by WPF Validation manager (it is the extensibility point):&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/R81nviV0QqI/AAAAAAAADZA/6SvTe5PJeFg/s1600-h/NextCmdQueryEnabled.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SD63VNldkZI/AAAAAAAAEvI/NIxoasNyFrI/s1600-h/NextCmdQueryEnabled1.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205799794338795922" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SD63VNldkZI/AAAAAAAAEvI/NIxoasNyFrI/s400/NextCmdQueryEnabled1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;This logic will be called automatically by WPF CommandManager and will reflect state of edited object on NextButton button.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;Extensibility point.&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Imagine a following scenario:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;you edit a credential object that is formed by a Login and Password properties. You have 1 TextBox - Login, and 2 PasswordBoxes - for Password and PasswordConfirmation. This credential object (lets call it LoginCredential) is in DataContext property of wizardpage. You have binded TextBox's Text property to a Login property of credential, text from first PasswordBox use assing to Password property of credential in code-behind. However, in order to validate a password you need user to confirm it and a LoginCrredential class doesn't have such a property (PasswordConfirmation) and never have to! How we will keep our Buttons' state syncronized wth data, when they should be inactive unless user has confirmed his password? &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SD6z-NldkYI/AAAAAAAAEvA/ZWOeZxpQgDQ/s1600-h/wizard2.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205796100666921346" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SD6z-NldkYI/AAAAAAAAEvA/ZWOeZxpQgDQ/s400/wizard2.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;Well, here is the place where I plug in a WPF validation process. In this case I don't need to validate business object's data and should validate only that part of data, which is located in UI.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I've written a ValidationHelper class to streamline my validation code.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SD69RNldkaI/AAAAAAAAEvQ/_ZmL8mT3BFQ/s1600-h/ValidationHelper1.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205806322689085858" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SD69RNldkaI/AAAAAAAAEvQ/_ZmL8mT3BFQ/s400/ValidationHelper1.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;There is an attachable property Bag, which can be attached to any DependencyObject and bound with some data (it is useful when you have no properties to bind).&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Back to our scenario you'll have to bind ValidationHelper.Bag on first PasswordBox to Password property of underlying credential. You have to do this because in PasswordBox a Password property is not a dependency property (I know that there is a security issue with my attached property take it as an example).&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R81-qyV0QwI/AAAAAAAADZw/IAbJKjkB2No/s1600-h/pwdBoxBinding.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173930820451451650" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R81-qyV0QwI/AAAAAAAADZw/IAbJKjkB2No/s400/pwdBoxBinding.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;The key element in integration is the PasswordValidationRule that can be seen in the picture above. It is a custom descendant of WPF ValidationRule class. I had to do some code-behind here because, as I've mentioned earlier, Password is not a dependecy property. In this code-behind I obtain binding expression for ValidationHelper.Bag property and force it to update source, thus forcing validation.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R82ALyV0QxI/AAAAAAAADZ4/OXcgkFuCYVI/s1600-h/pwdChangedHandler.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173932486898762514" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R82ALyV0QxI/AAAAAAAADZ4/OXcgkFuCYVI/s400/pwdChangedHandler.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;I need to send PasswordCopy and WizardPage objects from UI into my ValidationRule object that is not a DependencyObject and even isn't in Logical or VisualTree. What we need to do is to attach virtual branch to the LogicalTree and this problem was perfectly solved by Josh Smith. You can read about this approach in his &lt;/span&gt;&lt;a href="http://www.codeproject.com/KB/WPF/AttachingVirtualBranches.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;article&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;. Here’s a brief description. ValidationRule is not a descendant of DependencyObject class so you can't bind its properties, but you can write a surrogate DependencyObject descendant class that will keep one dependency property that can be bound with data. This data is being sent into the dummy holder in resources (DataContextBridge) by means of OneWayToSource binding. After that you can bind a surrogate object Value property to DataContextBridge.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;The only thing that left is to write code for ValidationRule. It compares original password string with its copy and mark a wizard page as invalid in case passwords are not identical:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/SD_YB9ldkbI/AAAAAAAAEvY/7eDuawCfx00/s1600-h/PwdValidationRule.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5206117222486741426" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/SD_YB9ldkbI/AAAAAAAAEvY/7eDuawCfx00/s400/PwdValidationRule.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;There are two methods in ValidationHelper - MarkInvalid and ClearInvalid that are simply wrappers around WPF Validation class. All that is required to make UI element compatible with ValidationHelper is to attach ValidationHelper.Bag property and bind it with itself (as it is done in WizardPage's default style). &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Well, here we are - our validation process in wizard is ready. &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;In a simple scenario all that developer will have to do is to mark entities with validation attributes, or even configure 'em in enterprise library configuration tool and nothing else. All the rest work will be done by wizard automatically absolutly in an absolutely transparent manner.&lt;br /&gt;&lt;br /&gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;P.S. sources are coming on a little bit later.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-2955130620840225924?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=P38UAw7O"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=OCGh5eLe"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/4bz9cyWyneI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/4bz9cyWyneI/business-objects-validation-in-wpf.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_aPBCtYeet9E/SD6z99ldkXI/AAAAAAAAEu4/kLqulzY8gG4/s72-c/wizard1.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/04/business-objects-validation-in-wpf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-5553964490535511480</guid><pubDate>Mon, 14 Apr 2008 09:40:00 +0000</pubDate><atom:updated>2008-04-16T12:33:17.663-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">patterns</category><category domain="http://www.blogger.com/atom/ns#">CAB</category><title>WPF command &amp; CAB command - run into one another</title><description>&lt;p&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;My previous post was dedicated to the set of classes that constitutes my DM-V-VM pattern implementation being an extension to the &lt;a href="http://msdn2.microsoft.com/en-us/library/aa480482.aspx"&gt;smart client software factory&lt;/a&gt; (SCSF - CAB based factory) &amp;amp; Kent Boogaart's &lt;a href="http://www.codeplex.com/scsfcontrib"&gt;SCSFContrib&lt;/a&gt; (WPF CAB extensions project). &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;An interesting point was ActionViewModel class that contains and binds all view's commands. But there is another implementation of &lt;a href="http://en.wikipedia.org/wiki/Command_pattern"&gt;command pattern&lt;/a&gt; in CAB. Which of them a smart programmer should use? What are the pros and cons of each variant?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;In CAB's command implementation you have access to an IoС-container and a whole lot of CAB's infrastructure (local services, resources, views). At the same time WPF command is tightly integrated in UI engine, and UI control is the WPF engine's problem. Is there a way to gain united advantages?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;The answer is yes and it follows below.&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;Honestly speaking there is an&lt;/span&gt; implementation of merged CAB and WPF commands in &lt;a href="http://kentb.blogspot.com/"&gt;Kent Boogaart's &lt;/a&gt;&lt;a href="http://www.codeplex.com/scsfcontrib"&gt;SCSFContrib&lt;/a&gt; project (WPF integration in CAB).&lt;/span&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;It is a &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;WrappedCabCommand, but I see a huge disadvantage in this implementation - it lacks ability to pass a parameter to a command. I solved this problem by extending Kent's approach.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;IActionCatalogService&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;My main enhancement to WrappedCabCommand is the use of CAB's local service&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt; IActionCatalogService as main command executor and state controller. &lt;a href="http://weblogs.asp.net/bsimser/archive/2007/10/26/taming-the-actioncatalog-in-scsf.aspx"&gt;Here&lt;/a&gt; you can find a good description of this SCSF part. This service links named actions with methods, marked with [Action(ActionName)] attribute,&lt;/span&gt; &lt;div&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8veNpS_miI/AAAAAAAADW4/H4VRiX4hnYY/s1600-h/ActImpl.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173472922970331682" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8veNpS_miI/AAAAAAAADW4/H4VRiX4hnYY/s400/ActImpl.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;registrers conditions - a code that controls action state (whether it can be executed or not),&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8vePJS_mlI/AAAAAAAADXQ/MTA3f_uHPnw/s1600-h/RegActCond.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173472948740135506" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8vePJS_mlI/AAAAAAAADXQ/MTA3f_uHPnw/s400/RegActCond.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;and allows executing named action (invokes a pipe of subscribed methods).&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8veOpS_mkI/AAAAAAAADXI/z1XhHTt3800/s1600-h/ExecActn.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173472940150200898" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8veOpS_mkI/AAAAAAAADXI/z1XhHTt3800/s400/ExecActn.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Method marked with [Action(ActionName)] attribute should be public and match an ActionDelegate delegate signature. Subscribing process is controlled by ActionStrategy from SCSF, that is plugged into the ObjectBuilder strategy chain. &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8vePJS_mmI/AAAAAAAADXY/pW0ZR0MswKY/s1600-h/RegActs.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173472948740135522" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8vePJS_mmI/AAAAAAAADXY/pW0ZR0MswKY/s400/RegActs.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Action conditions are classes that implement IActionCondition interface. Their respective method is automatically invoked by IActionCatalogService before executing, or it could be invoked externally by a client code through the same IActionCatalogService service. The service builds an action pipeline, and results an integral decision of all IActionCondition classes registered for concrete action.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8veOJS_mjI/AAAAAAAADXA/xlfl6DhJJik/s1600-h/ActnCond.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173472931560266290" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8veOJS_mjI/AAAAAAAADXA/xlfl6DhJJik/s400/ActnCond.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;СAB Command.&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Commands in CAB are a collection of Command objects stored in WorkItem and indexed by unique string identifier. CAB itself works with commands by means of &lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;CommandAdapter class, controling subscribers, command invokers etc. Commands are created by a CommandStrategy that is plugged in the ObjectBuilder strategies chain. Command is created when the strategy meets in created object public methods marked with [CommandHandler(CommandName)] attribute and matching the EventHandler delegate signature. CommandAdapter keeps internal invokers and subscribers tables for the named commands. And when it catches the specified event in invoker, WorkItem invokes all methods subscribed by means of [CommandHandler(CommandName)] attribute.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fngpS_mcI/AAAAAAAADWI/5EV0eGB7jIE/s1600-h/CABcmdAddInvoker.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5172357245085653442" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fngpS_mcI/AAAAAAAADWI/5EV0eGB7jIE/s400/CABcmdAddInvoker.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:78%;"&gt;Adding list view item as a ActivateOverview command invoker with Selected event&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:78%;"&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8fnhJS_mdI/AAAAAAAADWQ/GuxUG4feX_w/s1600-h/cmdHandlerCAB.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5172357253675588050" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8fnhJS_mdI/AAAAAAAADWQ/GuxUG4feX_w/s400/cmdHandlerCAB.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:78%;"&gt;ActivateOverview command's subscriber method. &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;WPF Command.&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;In WPF commands are presented by classe implementing &lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;ICommand interface. There are 2 built-in command classes in WPF library - RoutedCommand and RoutedUICommand. They routes their CanExecute and Executed events in a visual-tree as it follows from their name. The built-in commands doesn't contains any predefined logic and simply allows to handle it by any object from VisualTree that is subbscribed to this command via CommandBinding. UI elements, that can be binded to a command, should implement ICommandSource interface. This interface contains the following properties: Command - the command itself (ICommand), CommandParameter - parameter being passed to the command handler (optional property) and CommandTarget - target - an object particular command will be executed on (optional property).&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;Come together!&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;I've chosen a CommandModel class invented by Dan Crevier as a foundation for merged CAB and WPF commands entity.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fnhpS_meI/AAAAAAAADWY/NzWfRKZ2uo0/s1600-h/cmdModel.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5172357262265522658" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fnhpS_meI/AAAAAAAADWY/NzWfRKZ2uo0/s400/cmdModel.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;The ModuleCommand is the idea.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fpEpS_mfI/AAAAAAAADWg/0Nb8HdjRCDY/s1600-h/ModuleCmd.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5172358963072571890" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8fpEpS_mfI/AAAAAAAADWg/0Nb8HdjRCDY/s400/ModuleCmd.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:78%;"&gt;ModuleCommand class interface. IActionCatalogService is injected by CAB's IoC-container while created.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;This class finds a CAB command object by name &lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;- CommandName. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;I've made a convention in unique command naming, it is identifies by the following way - C&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;ommandName identifies Command and IActionCatalog Service action, CommandName with prefixes &lt;strong&gt;Before&lt;/strong&gt;[CommandName] and &lt;strong&gt;After&lt;/strong&gt;[CommandName] identifies command-triggers being executed before and after actual command execution respectively.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/R8vqZZS_msI/AAAAAAAADYI/HAOPguGS-EY/s1600-h/OnQueryEnabled.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173486318973328066" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/R8vqZZS_msI/AAAAAAAADYI/HAOPguGS-EY/s400/OnQueryEnabled.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;WPF invokes the ModuleCommand's object overrided &lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;OnQueryEnabled method automatically. It queries CAB command and ActionConditions if the command can be executed, promoting all the specific logic into the external infrastructure code (IActionCatalogService CanExecute call), and WPF reflects the command state in UI automatically - the UI element will be enabled or disabled.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;There is an ActionTarget property in a class - it is an optional parameter, that the command will pass to the subscribed method automatically by means of IActionCatalogService.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8f-PJS_mhI/AAAAAAAADWw/2Ep8dgg46-8/s1600-h/CmdOnExec.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5172382233205381650" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8f-PJS_mhI/AAAAAAAADWw/2Ep8dgg46-8/s400/CmdOnExec.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;WPF invokes the ModuleCommand's object overrided OnExecute method automatically when it catches event that triggers the command execution and delegates the execution to my ModuleCommand object that in turn delegates it to the Command and Action subscribers. &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Thus the problem of merging WPF and CAB commands is being solved by means of IActionCatalogService. UI element is binded with ModuleCommand by CommandBinding in a visual tree, and IActionCatalogService links ModuleCommand with the CAB infrastructure and allows to pass a target and parameter objects to a command handler. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;CAB command is still can be used when the logic is simple.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;I said work!&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Let's assemble an example now. We will modify the code from the previous post. Main changes will happen with &lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;FooViewModel class. There is only one type of command objects in it's collection now. There will be no more command classes with hardcoded logic.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/R8vou5S_mnI/AAAAAAAADXg/WvFGI2SO2ck/s1600-h/FooActnView.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173484489317259890" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/R8vou5S_mnI/AAAAAAAADXg/WvFGI2SO2ck/s400/FooActnView.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;but we'll need a command handler class and an action codition class. Here they are:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8vpHpS_moI/AAAAAAAADXo/iqM0NLqvsb4/s1600-h/FooActnImpl.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173484914519022210" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8vpHpS_moI/AAAAAAAADXo/iqM0NLqvsb4/s400/FooActnImpl.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8vpzpS_mpI/AAAAAAAADXw/IYw8lkoGJtA/s1600-h/FooActnCond.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173485670433266322" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8vpzpS_mpI/AAAAAAAADXw/IYw8lkoGJtA/s400/FooActnCond.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;+ unique strings list.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/R8vq95S_mtI/AAAAAAAADYQ/QDo04OTCcgo/s1600-h/CommandIdList.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5173486946038553298" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/R8vq95S_mtI/AAAAAAAADYQ/QDo04OTCcgo/s400/CommandIdList.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Code for download: &lt;a href="http://slil.ru/25696479"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Good luck!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;PS: A very interseting approach was demonstrated by wpf-rockstar Josh Smith in &lt;a href="http://www.codeproject.com/KB/WPF/SmartRoutedCommandsInWPF.aspx"&gt;this &lt;/a&gt;article&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;.&lt;/span&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;He suggests &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;to make RoutedCommand "smarter", by adding it an ability to keep logic itself. Josh inherits his class from RoutedCommand and introduces an attachable-property, marking UI element as a command handler, and also he introduces 2 abstract methods OnCanExecuteCore and OnExecuteCore to be overriden in descendant classes. Other words we could replace our CommandModel class with SmartRoutedCommand, but it would involve xaml complexity. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;PPS: remembered that I saw &lt;a href="http://geekswithblogs.net/rakker/archive/2008/02/14/119580.aspx"&gt;another approach&lt;/a&gt; that was built on CAB's EventBroker. But I don't like it though it is easier as it mixes the entities.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-5553964490535511480?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=fDBAJX1C"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=m03x7Lls"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/aUc5u1wry1s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/aUc5u1wry1s/wpf-command-cab-command-run-into-one.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_aPBCtYeet9E/R8veNpS_miI/AAAAAAAADW4/H4VRiX4hnYY/s72-c/ActImpl.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/04/wpf-command-cab-command-run-into-one.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-8363326232650740497</guid><pubDate>Tue, 08 Apr 2008 10:09:00 +0000</pubDate><atom:updated>2008-07-20T09:58:32.487-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">patterns</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><title>DataModel-View-ViewModel in WPF. Part 3 Example.</title><description>&lt;div style="font-family: verdana;"&gt;&lt;span style=";font-size:85%;" &gt;This is the last part on DM-V-VM pattern overview. In this part we'll write a simple WPF application built on this pattern. &lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="font-family: verdana;"&gt;&lt;span style=";font-size:85%;" &gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;DM-V-VM&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="font-family: verdana;"&gt;&lt;span style=";font-size:85%;" &gt;Let's suppose that we have an object of class Foo that is provided by the SEModel class (parameterized with Foo and FooProvider types). It will be a demonstration of simplicity that SEModel gives - we don't have to write datamodel class, only provider class will be written.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://4.bp.blogspot.com/_aPBCtYeet9E/R8U-ukYCcvI/AAAAAAAADKg/WSv1h1qwfR4/s1600-h/Foo.png"&gt;&lt;span style=""&gt;&lt;img id="BLOGGER_PHOTO_ID_5171608716864287474" style="" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/R8U-ukYCcvI/AAAAAAAADKg/WSv1h1qwfR4/s400/Foo.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/R_9Yd8dNLbI/AAAAAAAAD3g/iYwvRcRhUig/s1600-h/FooProv.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5187962567222177202" style="" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/R_9Yd8dNLbI/AAAAAAAAD3g/iYwvRcRhUig/s400/FooProv.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All the logic is contained in a FooViewModel class. It is derived from ActionsViewModel as we'll have some actions triggers in UI (buttons). The actions are represented by two CommandModels - IncCommandModel and DecCommandModel. IncCommandModel increments Foo.Bar property when executed and DecCommandModel decrements it respectively. The DataModel is asked to refresh on View's Load event. DataModel will fetch data asyncronously and throw an event on UI thread as described in a &lt;a href="http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-1.html"&gt;first post&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R_9YeMdNLcI/AAAAAAAAD3o/JkL07QNAquk/s1600-h/FooVM.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5187962571517144514" style="" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R_9YeMdNLcI/AAAAAAAAD3o/JkL07QNAquk/s400/FooVM.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: verdana;"&gt; &lt;/div&gt;&lt;div style="font-family: verdana;"&gt;&lt;span style=";font-size:85%;" &gt;CommandModel classes implements logic for editing underlying data (Foo object) that is referenced in CommandParameter property of UI command triggers (objects that implement &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.input.icommandsource.aspx"&gt;ICommandSource&lt;/a&gt; interface - Buttons in our example).&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/R8U-wEYCcyI/AAAAAAAADK4/MMJh9mwm7a4/s1600-h/VMComm.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171608742634091298" style="" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/R8U-wEYCcyI/AAAAAAAADK4/MMJh9mwm7a4/s400/VMComm.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style="font-family: verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;Now it is a view's turn.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;In this example we won't use an IoC-container and will hardcode all dependecies in our classes. View creates ViewModel on it's Initialized event.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://3.bp.blogspot.com/_aPBCtYeet9E/R_9YeMdNLdI/AAAAAAAAD3w/u9D62yulCnE/s1600-h/FooView.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5187962571517144530" style="" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R_9YeMdNLdI/AAAAAAAAD3w/u9D62yulCnE/s400/FooView.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;And keeping in mind that ViewModel sets itself to the DataContext property of View (window in our case) we know that all visual tree of our view will inherit VM in DataContext property. So just put a ContentControl in a view, bind it's Content property to VM and write a template to render VM.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://4.bp.blogspot.com/_aPBCtYeet9E/R_9YecdNLeI/AAAAAAAAD34/vtAfKdlBqLU/s1600-h/FooViewXaml.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5187962575812111842" style="" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/R_9YecdNLeI/AAAAAAAAD34/vtAfKdlBqLU/s400/FooViewXaml.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;The only evil SEModel can bring - is lack of ability to bind to it's Entity property. DataBinding just can't fetch the object even if all paths are accurate in 2 or more level templates. But this issue can be avoided easily - just put your object in View's resources in DataModelLoaded event in ViewModel and reference it in Binding via Source property.&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://4.bp.blogspot.com/_aPBCtYeet9E/R8VsokYCc1I/AAAAAAAADLQ/vSlx5FO9I80/s1600-h/VMModelLoaded.png"&gt;&lt;span style=""&gt;&lt;img id="BLOGGER_PHOTO_ID_5171659191319950162" style="" alt="" src="http://4.bp.blogspot.com/_aPBCtYeet9E/R8VsokYCc1I/AAAAAAAADLQ/vSlx5FO9I80/s400/VMModelLoaded.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;This is how our application looks like:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8VtDUYCc2I/AAAAAAAADLY/E-DW_cQlQlk/s1600-h/FooApp.png"&gt;&lt;span style=""&gt;&lt;img id="BLOGGER_PHOTO_ID_5171659650881450850" style="" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8VtDUYCc2I/AAAAAAAADLY/E-DW_cQlQlk/s400/FooApp.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;br /&gt;Source for download: &lt;a href="http://www.megaupload.com/ru/?d=OEWPQ15D"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;p style="font-family: verdana;"&gt;&lt;span style=";font-size:85%;" &gt;Good luck!&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: verdana;font-family:verdana;font-size:85%;"  &gt;PS: PnP group will finish their new project called - &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://www.codeplex.com/prism"&gt;&lt;span style=""&gt;Prism&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-size:85%;" &gt;, soon. It is intended to become CAB's replacement in developing LOB applications with WPF. Check for weekly drops &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: verdana;" href="http://www.codeplex.com/prism/Release/ProjectReleases.aspx"&gt;&lt;span style=""&gt;here&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-size:85%;" &gt;.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-8363326232650740497?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=zeET3JXK"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=xswvkrJI"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/ngzh6GBvDXk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/ngzh6GBvDXk/datamodel-view-viewmodel-in-wpf-part-3.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_aPBCtYeet9E/R8U-ukYCcvI/AAAAAAAADKg/WSv1h1qwfR4/s72-c/Foo.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-3.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-4378191441327932320</guid><pubDate>Tue, 08 Apr 2008 10:07:00 +0000</pubDate><atom:updated>2008-04-11T02:15:29.765-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">patterns</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><title>DataModel-View-ViewModel in WPF. Part 2 View and ViewModel.</title><description>&lt;span style="font-family:verdana;font-size:85%;"&gt;This is the second part on my DataModel-View-ViewModel overview. In the &lt;a href="http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-1.html"&gt;previous part&lt;/a&gt; I was talking about DM classes which are intended to supply presentation layer that is composed of the View and ViewModel with data. Let's look at this View and ViewModel.&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;View is just a view (a xaml + codebehind class) and nothing more. It shouldn't keep any state or implement any logic operations except ones that relates to rendering.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;VM doesn't "know" the view class and "speaks" with it through the IView interface. As I've mentioned earlier VM doesn't let you to switch UI framework without code review as ViewModel is tightly coupled with WPF-specific entities (such as &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms752308.aspx"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;commands&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;), so for simplicity's sake I've promoted a IWPFView interface that consists of WPF-specific properties and events.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8UtL0YCcsI/AAAAAAAADKI/pKC_baM_-CA/s1600-h/IV.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171589428166161090" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8UtL0YCcsI/AAAAAAAADKI/pKC_baM_-CA/s400/IV.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ViewModel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;And at last main trinity's player. This class keeps all view related logic and state. My base VM class is parameterized vith view interface and it's descendant is parameterized with DM interface. Using CAB's IoC-container I resolve all of VM dependencies and inject it (VM) into View.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8Uv-UYCctI/AAAAAAAADKQ/inovHoqZtiE/s1600-h/VM.png"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171592494772810450" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8Uv-UYCctI/AAAAAAAADKQ/inovHoqZtiE/s400/VM.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;This classes have a bunch of useful virtual methods that are fired when View/DataModel set/unset events happen, in DataModel Loaded/ExceptionCatched events and View's Loaded/Unloaded. In a base class VM sets itself to a view's DataContext property, thus enabling it to update itself by DM, business objects and VM change events catching in databinding. So, speaking in Martin Fowler's words view in WPF is an ActiveView.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;You can also find an ActionsViewModel on the diagram above. This class keeps a &lt;a href="http://blogs.msdn.com/dancre/archive/2006/09/15/dm-v-vm-part-7-encapsulating-commands.aspx"&gt;CommandModel&lt;/a&gt; objects list (very useful approach to wrap wpf command from Dan Crevier). For every command VM creates a command binding in a view automaticly.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;ViewModel doesn't prohibit you from editing business object supplied by DM in UI and doesn't makes any validations of unedrlying data. So to avoid errors of this kind all of my objects are being edited in wizard UI (I've written a custom WPF control for it. I'll propably write about it later) that tracks object state and avoids saving invalid objects. But if you want to edit objects in your UI in a simple way you propably should read &lt;a href="http://www.acceptedeclectic.com/2008/01/model-view-viewmodel-pattern-for-wpf.html"&gt;this article from Pete W&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;That is all on View and ViewModel. In next part I'll assemble a simple example and (as I promised before) I'll include a sample code.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Good luck!&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-4378191441327932320?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=cnPwMsID"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=rBbrerAq"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/jPeiLTxFrpA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/jPeiLTxFrpA/datamodel-view-viewmodel-in-wpf-part-2.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_aPBCtYeet9E/R8UtL0YCcsI/AAAAAAAADKI/pKC_baM_-CA/s72-c/IV.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-2.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2051886115581731342.post-3247231612108507226</guid><pubDate>Sat, 05 Apr 2008 11:04:00 +0000</pubDate><atom:updated>2008-04-09T13:13:13.592-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">patterns</category><category domain="http://www.blogger.com/atom/ns#">DM-V-VM</category><title>DataModel-View-ViewModel in WPF. Part 1 DataModel.</title><description>&lt;span style="font-family:Verdana;"&gt;&lt;span style="font-size:85%;"&gt;All of my UIs are built on very powerful pattern called &lt;a href="http://blogs.msdn.com/dancre/archive/2006/10/11/datamodel-view-viewmodel-pattern-series.aspx"&gt;DataModel-View-ViewModel&lt;/a&gt; (DM-V-VM) that was first described by Dan Crevier. I've written a small "framework" (I better say set of classes) to enhance it to my needs. &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span style="font-size:85%;"&gt;We have chosen a WPF UI framework in conjuction with the &lt;a href="http://msdn2.microsoft.com/en-us/library/aa480450.aspx"&gt;Composite Application Block&lt;/a&gt; (CAB) and &lt;a href="http://msdn2.microsoft.com/en-us/library/aa480482.aspx"&gt;SmartClient Software Factory&lt;/a&gt; (SCSF) to be the foundation of the presentation layer for the project. CAB stimulates and actively using another two UI patterns &lt;a href="http://en.wikipedia.org/wiki/Model-view-controller"&gt;Model-View-Controller&lt;/a&gt; (M-V-C) and &lt;a href="http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/default.aspx"&gt;Model-View-Presenter&lt;/a&gt; (M-V-P). So my set of classes is an extension to an existing infrastracture that uses some of the built-in CAB functionality, especialy &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_Control"&gt;IoC&lt;/a&gt;-container to resolve dependencies of my classes.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;DM-V-VM pattern is a special case of another more brief UI pattern - M-V-P. Martin Fowler calls it the &lt;/span&gt;&lt;a href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;&lt;span style="font-size:85%;"&gt;PresentationModel&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;. There is one problem with this pattern - it is fantastic in WPF, but you won't be able to switch to another UI technology without rewriting some code (&lt;a href="http://drwpf.com/Blog/Default.aspx?tabid=36&amp;amp;EntryID=27"&gt;you can read some on this in Dr.WPF blog&lt;/a&gt;). And if it is an evil you can live with than this pattern will be the best choice. And may be it will become too complex to maintain your code when you will have more then 5 data sources. In this case I would recomend you to switch to the M-V-P pattern.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;So let's go on.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;strong&gt;DataModel(DM)&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;Classes that provide data (business objects). Their duty is to provide data in WPF-friendly way (at least to implement INotifyPropertyChanged). All the properties and some of methods should only be accessed from UI thread, and it is strongly recommended not to block the UI thread for long.&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;I think that DM classes (as they were described by Dan Crevier) perfectly fits SOA way of programming, being a data gateway from services to UI.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;But services are not the only possible source of data, it can be anything - a file in a file system, for example. To make DM classes lossely-coupled with this different data sources there are providers system that is delegated to obtain data (a &lt;a href="http://en.wikipedia.org/wiki/Strategy_pattern"&gt;strategy&lt;/a&gt; by GoF).&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;A foundation for my DM classes is the Dan Crevier's implementation of DM-V-VM pattern so I shall concentrate on my enhancments instead of rewriting code here.&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;ol&gt;&lt;li&gt;The first thing to come is the base interface for DM classes with the couple of inherited generic interfaces that are narrows (or should I say precises) DM functionality by restricting Entity and Provider types.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The second thing is the typed provider interface.&lt;/li&gt;&lt;a href="http://1.bp.blogspot.com/_aPBCtYeet9E/R8RdCEYCcpI/AAAAAAAADJw/ziQCju5WuJI/s1600-h/IDM.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171360562243859090" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aPBCtYeet9E/R8RdCEYCcpI/AAAAAAAADJw/ziQCju5WuJI/s400/IDM.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Base DM class is the third thing. It contains a bunch of asyncronous methods (load complete notification, exception catched notification, etc.) plus a set of virtual methods to be overriden in descendant classes.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_aPBCtYeet9E/R8Vt5EYCc3I/AAAAAAAADLg/0mRN1aOR2W4/s1600-h/DM.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171660574299419506" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aPBCtYeet9E/R8Vt5EYCc3I/AAAAAAAADLg/0mRN1aOR2W4/s400/DM.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Invention of generic provider enabled me to write generic DM class that is parameterized with an entity type and typed provider (typed by entity type). I've called it SingleEntityModel. This class frees you from writing lots of DM descendants with the only duty to provide some Entity.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_aPBCtYeet9E/R8RiCkYCcrI/AAAAAAAADKA/EhqBR_DbBIY/s1600-h/SEDM.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5171366068391932594" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aPBCtYeet9E/R8RiCkYCcrI/AAAAAAAADKA/EhqBR_DbBIY/s400/SEDM.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;All the clients work with the DM objects through their interfaces as they are treated as a local services and can be injected in dependent code by an &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control"&gt;IoC-container&lt;/a&gt;. &lt;br /&gt;&lt;/div&gt;&lt;div&gt;That is all on DataModel, check for new parts.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;Good luck!&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;PS: I will include code in a later parts.&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2051886115581731342-3247231612108507226?l=robbbloggg.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=uUQtWmAm"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/blogspot/robbbloggg?a=Q3aEwV3Y"&gt;&lt;img src="http://feeds.feedburner.com/~f/blogspot/robbbloggg?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/robbbloggg/~4/Wpp-hGBnnLg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/robbbloggg/~3/Wpp-hGBnnLg/datamodel-view-viewmodel-in-wpf-part-1.html</link><author>noreply@blogger.com (RobertT)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_aPBCtYeet9E/R8RdCEYCcpI/AAAAAAAADJw/ziQCju5WuJI/s72-c/IDM.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://robbbloggg.blogspot.com/2008/04/datamodel-view-viewmodel-in-wpf-part-1.html</feedburner:origLink></item></channel></rss>

