<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ASPCode.net</title>
	<atom:link href="http://aspcode.net/feed" rel="self" type="application/rss+xml" />
	<link>http://aspcode.net</link>
	<description>Free asp.net and asp scripts</description>
	<lastBuildDate>Thu, 09 Sep 2010 11:57:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Last Git Commit as a MSBuild Task</title>
		<link>http://aspcode.net/last-git-commit-as-a-msbuild-task</link>
		<comments>http://aspcode.net/last-git-commit-as-a-msbuild-task#comments</comments>
		<pubDate>Thu, 09 Sep 2010 11:50:10 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1037</guid>
		<description><![CDATA[Time for a tiny small free tool. But just what I needed, so therefore I developed it&#8230;
I often do solutionwide versioning. As in generatinig the AssemblyInfo.cs files when building a the deploy target. Before I come that far I just code, build and test in Visual Studio, but go out to the command prompt when [...]]]></description>
			<content:encoded><![CDATA[<p>Time for a tiny small free tool. But just what I needed, so therefore I developed it&#8230;</p>
<p>I often do solutionwide versioning. As in generatinig the AssemblyInfo.cs files when building a the deploy target. Before I come that far I just code, build and test in Visual Studio, but go out to the command prompt when the fix is tested and done. Cause I gotta do git commit anyway.</p>
<p>The first thing I do is set a new version number in my MSBuild file. It uses MSBuild Community Tasks for a lot of things, generating AssemblyInfo files being one.</p>
<p>&lt;PropertyGroup Label=&#8221;versioning&#8221;&gt;<br />
&lt;versioningMajor&gt;1&lt;/versioningMajor&gt;<br />
&lt;versioningMinor&gt;0&lt;/versioningMinor&gt;<br />
&lt;versioningBuild&gt;0&lt;/versioningBuild&gt;<br />
&lt;versioningRevision&gt;0&lt;/versioningRevision&gt;<br />
&lt;/PropertyGroup&gt;</p>
<p>&lt;AssemblyInfo CodeLanguage=&#8221;CS&#8221;<br />
OutputFile=&#8221;ReportUpdater\Properties\AssemblyInfo.cs&#8221;<br />
AssemblyTitle=&#8221;ReportUpdater&#8221;<br />
AssemblyDescription=&#8221;ReportUpdater&#8221;<br />
AssemblyCompany=&#8221;Systementor AB&#8221;<br />
AssemblyProduct=&#8221;ReportUpdater&#8221;<br />
AssemblyCopyright=&#8221;Copyright Systementor AB 2010&#8243;<br />
ComVisible=&#8221;false&#8221;<br />
CLSCompliant=&#8221;false&#8221;<br />
AssemblyVersion=&#8221;$(versioningMajor).$(versioningMinor).$(versioningBuild).$(versioningRevision)&#8221;<br />
AssemblyFileVersion=&#8221;$(versioningMajor).$(versioningMinor).$(versioningBuild).$(versioningRevision)&#8221;<br />
/&gt;</p>
<p>Anyway, one of the problems with git is we dont easily get a numeric version number to use in our fileversion. So what I wanted to have was something like this:</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/LastCommitGitMSBuild.png"><img class="alignnone size-full wp-image-1040" title="LastCommitGitMSBuild" src="http://aspcode.net/wp-content/uploads/2010/09/LastCommitGitMSBuild.png" alt="" width="368" height="510" /></a></p>
<p>Some sort of connection to the last Git commit hash.</p>
<p>So therefore I had to code my very first MSBuild Task.</p>
<p><a href="http://github.com/aspcodenet/Git-Last-commit--version--as-MSBuild-Task">Download MSTask for Git Latest Commit here</a></p>
<p>binary is here <a href="http://github.com/downloads/aspcodenet/Git-Last-commit--version--as-MSBuild-Task/GitVersion.zip">http://github.com/downloads/aspcodenet/Git-Last-commit&#8211;version&#8211;as-MSBuild-Task/GitVersion.zip</a></p>
<p>How to use it:</p>
<p>&lt;UsingTask AssemblyFile=&#8221;\code\tools\MSBuildTasks\GitVersion.dll&#8221;<br />
TaskName=&#8221;GitVersion&#8221;/&gt;</p>
<p>&lt;PropertyGroup Label=&#8221;versioning&#8221;&gt;<br />
&lt;versioningMajor&gt;1&lt;/versioningMajor&gt;<br />
&lt;versioningMinor&gt;0&lt;/versioningMinor&gt;<br />
&lt;versioningBuild&gt;0&lt;/versioningBuild&gt;<br />
&lt;versioningRevision&gt;0&lt;/versioningRevision&gt;<br />
&lt;LastCommit&gt;not avail&lt;/LastCommit&gt;<br />
&lt;/PropertyGroup&gt;</p>
<p>&lt;GitVersion LocalPath=&#8221;$(MSBuildProjectDirectory)&#8221;&gt;<br />
&lt;Output TaskParameter=&#8221;LastCommit&#8221; PropertyName=&#8221;LastCommit&#8221; /&gt;<br />
&lt;/GitVersion&gt;</p>
<p>&lt;AssemblyInfo CodeLanguage=&#8221;CS&#8221;<br />
OutputFile=&#8221;ReportUpdater\Properties\AssemblyInfo.cs&#8221;<br />
AssemblyTitle=&#8221;ReportUpdater Last commit:$(LastCommit)&#8221;<br />
AssemblyDescription=&#8221;ReportUpdater&#8221;<br />
AssemblyCompany=&#8221;Systementor AB&#8221;<br />
AssemblyProduct=&#8221;ReportUpdater&#8221;<br />
AssemblyCopyright=&#8221;Copyright Systementor AB 2010&#8243;<br />
ComVisible=&#8221;false&#8221;<br />
CLSCompliant=&#8221;false&#8221;<br />
AssemblyVersion=&#8221;$(versioningMajor).$(versioningMinor).$(versioningBuild).$(versioningRevision)&#8221;<br />
AssemblyFileVersion=&#8221;$(versioningMajor).$(versioningMinor).$(versioningBuild).$(versioningRevision)&#8221;<br />
/&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/last-git-commit-as-a-msbuild-task/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I dont use a queue to publish my events to read model and others</title>
		<link>http://aspcode.net/why-i-dont-use-a-queue-to-publish-my-events-to-read-model-and-others</link>
		<comments>http://aspcode.net/why-i-dont-use-a-queue-to-publish-my-events-to-read-model-and-others#comments</comments>
		<pubDate>Tue, 07 Sep 2010 07:27:52 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1029</guid>
		<description><![CDATA[Question: I have looked at the architechtural diagram

and I look in the CQRS example sourcecode, expecially for the ReadModelupdater http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/Program.cs plus http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/LogChaser.cs and what bothers me is what you do is polling!!! Polling against a SQL Server database? Why not have CommandHandler publish the events to a queue as well as storing it into the [...]]]></description>
			<content:encoded><![CDATA[<p>Question: I have looked at the architechtural diagram</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture4.png"><img class="alignnone size-medium wp-image-1000" title="CropperCapture[4]" src="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture4-273x300.png" alt="" width="273" height="300" /></a></p>
<p>and I look in the <a href="http://github.com/aspcodenet/CQRS-demo-20100906">CQRS example sourcecode</a>, expecially for the ReadModelupdater <a href="http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/Program.cs">http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/Program.cs</a> plus <a href="http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/LogChaser.cs">http://github.com/aspcodenet/CQRS-demo-20100906/blob/master/Demo/ReadModelUpdater/LogChaser.cs</a> and what bothers me is what you do is polling!!! Polling against a SQL Server database? Why not have CommandHandler publish the events to a queue as well as storing it into the eventstore.</p>
<p>Fair question. And it deserves an answer as its one of the design choices I have made. Lets look at what it means:</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/cqrs.png"><img class="alignnone size-medium wp-image-1030" title="cqrs" src="http://aspcode.net/wp-content/uploads/2010/09/cqrs-233x300.png" alt="" width="233" height="300" /></a></p>
<p>That is much nicer. However the BIG problem we have here is now our CommandHandler &#8211; meant to execute behaviour on our domain (business logic) &#8211; now have another thing it is supposed to do. It has to send a message to the queue as well. From a design view I really like to keep things clear. One process one task. And the biggest problem is this: what happens if there is an error when sending it to the queue? Our business logic functions performed as according to plan but the outgoing msmq is malfunctioning for some whatever reason? That is totally unacceptable.</p>
<p>In practice it also means a longer total transaction length (maybe 2pc) since it now involves the outgoing queue as well.</p>
<p>I actually lied in my header about not using a queue. In effect our SQL Server database (eventstore) IS a perfect queue. By having each listener keep track of where it left off we have indeed a solid  publisher/subscriber  solution.</p>
<p>Now, in cases where we really need to publish to a &#8220;real&#8221; queue, like to an external system or whatever, we can do that as well. But we dont do it from the commandhandler. Look at this</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/cqrs22.png"><img class="alignnone size-medium wp-image-1031" title="cqrs22" src="http://aspcode.net/wp-content/uploads/2010/09/cqrs22-233x300.png" alt="" width="233" height="300" /></a></p>
<p>In this example I have even modified the Readmodelupdater to read from the queue, but that was just to show you you can do that as well. My point is to keep commandhandler do nothing but business logic. Mimimize the risk of failure.</p>
<p>Last: the polling has a sleep(5000 milliseconds).   Where does that number come from? You simply have to ask the stakeholders. What is acceptable SLA. As we are doing CQRS we are allowing eventual consistancy. Now the question is how long before it has to be consistant.</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/why-i-dont-use-a-queue-to-publish-my-events-to-read-model-and-others/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the same day</title>
		<link>http://aspcode.net/on-the-same-day</link>
		<comments>http://aspcode.net/on-the-same-day#comments</comments>
		<pubDate>Mon, 06 Sep 2010 21:07:32 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1023</guid>
		<description><![CDATA[Same day I published the first two posts of my CQRS example serie, one of them being http://aspcode.net/the-problem-with-how-we-save-data-today Orin published an article on kind of the same matter, Normalization is from the devil .
Coincidence, yes, but still, it kind of gives me confidence this is the way we are heading. Databases as we know it [...]]]></description>
			<content:encoded><![CDATA[<p>Same day I published the first two posts of my CQRS example serie, one of them being <a href="http://aspcode.net/the-problem-with-how-we-save-data-today">http://aspcode.net/the-problem-with-how-we-save-data-today</a> Orin published an article on kind of the same matter, <a href="http://ayende.com/Blog/archive/2010/09/06/normalization-is-from-the-devil.aspx">Normalization is from the devil</a> .</p>
<p>Coincidence, yes, but still, it kind of gives me confidence this is the way we are heading. Databases as we know it today (3NF) are not here to stay forever.</p>
<p>Do I need to say I  pretty much agree with Orin on this matter.  Consistency boundaries based on behaviour is what makes up my models. Basically we need to stop thinking data and nouns. Why would we say the second model In Orins example is denormalized? Some might say it&#8217;s because we have &#8220;ProductName&#8221; in two places. Yes, if a &#8220;product&#8221; is the same thing as a &#8220;ordered product&#8221;. And it&#8217;s not 100% sure it is&#8230;as in &#8220;hanged the product name from “Thingamajig” to “Foomiester”, mighty confusing for me when I look at that order and have no idea what that thing was&#8221;</p>
<p>Where he kind of misses is taking the next step:  the real key is to being happy with the model as it is right now. Its good for commands and executing behaviour. Lets now just call it write model.</p>
<p>Reporting/reading data is another business. Generating a specific report model based on the changes made to the write model. So lets call the new model &#8220;read model&#8221;. Have it updated asynchronously from changes from write model.</p>
<p>Thing is for write model, denormalization is still a good thing to avoid (but not the end of the world either), but<br />
when it comes to pure read models, denormalization is really ok.</p>
<p>All in all, the beauty of CQRS.</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/on-the-same-day/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS loosly coupled sample</title>
		<link>http://aspcode.net/cqrs-loosly-coupled-sample</link>
		<comments>http://aspcode.net/cqrs-loosly-coupled-sample#comments</comments>
		<pubDate>Mon, 06 Sep 2010 15:07:21 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1018</guid>
		<description><![CDATA[Ok,. in these two earlier posts I talk about the whys.
http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui
http://aspcode.net/the-problem-with-how-we-save-data-today
Now lets get into the how. Fiorst start by downloading the CQRS example from githib.
This pretty much implements the architechure layed out in this diagram

I will do some complimentary lowlevel posts later, but this one need to come first.
Choices I&#8217;ve made
- I have chosen Castle/Windsor [...]]]></description>
			<content:encoded><![CDATA[<p>Ok,. in these two earlier posts I talk about the whys.</p>
<p><a href="http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui">http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui</a></p>
<p><a href="http://aspcode.net/the-problem-with-how-we-save-data-today">http://aspcode.net/the-problem-with-how-we-save-data-today</a></p>
<p>Now lets get into the how. Fiorst start by downloading the <a href="http://github.com/aspcodenet/CQRS-demo-20100906">CQRS example</a> from githib.</p>
<p>This pretty much implements the architechure layed out in this diagram</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture41.png"><img class="alignnone size-medium wp-image-1019" title="CropperCapture[4]" src="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture41-273x300.png" alt="" width="273" height="300" /></a></p>
<p>I will do some complimentary lowlevel posts later, but this one need to come first.</p>
<p><strong>Choices I&#8217;ve made</strong></p>
<p>- I have chosen Castle/Windsor for IOC</p>
<p>- I have chosen RhinoEBS as bus</p>
<p>- I have chosen SQL Server as eventstore. Although I do have another driver implementing the IEventStore interface which I use internally. I&#8217;ll might get into that in a later post</p>
<p>- I have chosen Protobuf-net for serialization</p>
<p><strong>What does the application do?</strong></p>
<p>Its a fake GymMember application. A Windows Forms GUI (GymGUI) allowing you to view/search the members. Doubleclick on a member to Upgrade/Downgrade the level.</p>
<p>GoldMember is implemented by business rule: I think it was like if trained 12 times in 30 days they get upgraded to gold member. If they then dont train at least 10 times in last 60 days they gets downgraded. The idea is to have (nightly) batch use the CheckGoldMemberStatus command to have it calculated each night. But as I said, much havn&#8217;t been done, point is to show the infrastructure.</p>
<p><strong>Projects in solution</strong></p>
<p>Bus &#8211; just a helper for command dispatching when chasing the eventstore (used by ReadModel updater)</p>
<p>Eventing &#8211; infrastructure for eventsourcing &#8211; and eventhandling in general</p>
<p>EventStoreSQL &#8211; implements IEventStore interface and is a driver for SQL Server</p>
<p>GoldGymMemberCommandHandler &#8211; command handler (look at picture). Receives messages from client(s). Executes domain behaviour</p>
<p>GoldGymMemberDomain &#8211; business logic</p>
<p>GymGoldMemberCommands &#8211; commands. Client sends commands to CommandHandler</p>
<p>GymGoldMemberEvents &#8211; events. Business logic (domain) publishes events. Please note that I use the eventstore database as queue &#8211; all eventhandling is done asynchronously and in other processes</p>
<p>GymGoldMemberRepositories &#8211; implementation of GoldGymMemberDomain.Ports.IGymMemberRepository</p>
<p>GymGUI &#8211; client app (WIndows Forms)</p>
<p>ReadModelUpdater &#8211; asynch process to update the read model</p>
<p>To get it running you need to:  run SQL Server database.txt to create the database tables, change app.config wherever there is a sql connectionstring to point to that database. Make sure MSMQ is up and running.</p>
<p>The key part is starting GoldGymMemberCommandHandler first so the queue gets created.</p>
<p>Typically you should have GoldGymMemberCommandHandler, ReadModelUpdater running ALL the time.</p>
<p>-</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/cqrs-loosly-coupled-sample/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The problem with how we save data today</title>
		<link>http://aspcode.net/the-problem-with-how-we-save-data-today</link>
		<comments>http://aspcode.net/the-problem-with-how-we-save-data-today#comments</comments>
		<pubDate>Mon, 06 Sep 2010 14:37:51 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1015</guid>
		<description><![CDATA[This is a continuation of a series of CQRS posts starting with http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui
Let me ask you. When you are faced a new business problem, where do you start? Do you start by trying to model the database. Maybe with UML you try to create a third normal form model from which to base your business [...]]]></description>
			<content:encoded><![CDATA[<p>This is a continuation of a series of CQRS posts starting with <a href="http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui">http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui</a></p>
<p>Let me ask you. When you are faced a new business problem, where do you start? Do you start by trying to model the database. Maybe with UML you try to create a third normal form model from which to base your business logic from. Maybe even using NHibernate or Entity Framework 4 to get the base classes and loading/saving/updating for free. Hehe, now all we need to do is implement the business logic <img src='http://aspcode.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now after a few month the boss comes telling you there has been security problems  in your application and you&#8217;ll need to start logging ALL changes done to it. Ok, since you are using SQL Server, why not whip up some clever triggers for each and every table. Whenever a column is updated our trigger will insert a row to a logtable, along with date, table, column, who dot it etc. Trust me, I actually have heard a developer being proud of managing to implement such a solution.</p>
<p>Lets start from the beginning: Why do we want to create our database in 3NF? Well, we have been told so. It&#8217;s reasonable fast for inserts/updates as there are no duplicates. So, to be honest, for our domain model is is not such a bad choice. There is of course a risk of having many many tables being involved in a single transaction, therefore needing multiple locks &#8211; and longer running transactions as well.</p>
<p>For pure reading, 3NF is NOT good. Wouldn&#8217;t the optimal table structure be one table per DTO, as in for each form our GUIs need to present, data has been precalculated and all we do is &#8220;select * from  formcustomers_dto1 where id=&#8230;&#8221;.  Instead, what we often do is call our business layer to load up the object graph needed, use something like AutoMapper or handcode the DTO creation where we do aggregates or simple just pick out the few fields actually needed. Or even worse, we send the whole entities to our client, edit data, send it back to our business logic  layer &#8211; then we use an ORM to calculate the delta (changes) and save it.</p>
<p>Ok, we can agree the type of databases we develop today (using UML/3NF approach) are reasonable for writing, bad for reading. Now go back to your own system and think about how many percent of the database accesses are made for pure reading or writing&#8230;</p>
<p>Ok, so far I&#8217;m just outlining some problems we have when we develop like we do today. Next, even bigger problem, is what I started off with. The fact that we typically just store current state. In some cases we do introduce &#8220;logging&#8221; tables. But all to often its too late. We add it after the fact. Simple, we have no possibility to foresee future business requirements , so why don&#8217;t we make it a rule to ALWAYS store a full log of state changes?</p>
<p>Simply because of costs. It costs diskspace. It costs development time, we need our DBAs to create logtables for each our &#8220;real&#8221; tables, there is also a storage cost. And what happens when we add a new field to our business class. We then need to add it to our logtable, and TWO ORM mappings must be  redone etc.</p>
<p>The answer to all these toubles are in a concept called eventsourcing. Now before I move on I wanna make it clear. Its a lot of fun coding &#8211; at a much lower level than needed for the ORM/SQL approach, and me being a tech nerd of course loves that, but the fact is, we do it for business reasons. Imagine the first example again with &#8220;the boss comes telling you there has been security problems  in your application and you&#8217;ll need to start logging&#8221;. You say, we already are. Tell me what I should look for and I can easily see who the offender was, what he did. Oh it did happen 10 years ago. No problem. Just tell me anyway, I&#8217;ll have it for you  without even needing to restore a backup.</p>
<p>And performance reasons. Imaging having a table where you never read/update data. All you do is insert. Thats pretty much all that ever ever happens inside a transaction the CQRS style.  Earlier (3NF style) a transaction might have involved ten or twenty different tables. Insert/update whatever with locking. Now we do insert statechanges. Thats it. And we have NO other processes/users needing to aquire readlocks on the table.</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/the-problem-with-how-we-save-data-today/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>No CRUD &#8211; allow for saving user intent in your GUI</title>
		<link>http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui</link>
		<comments>http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui#comments</comments>
		<pubDate>Mon, 06 Sep 2010 13:59:04 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=1007</guid>
		<description><![CDATA[Ok, say we have a member database.  Entity is &#8220;Member&#8221;, fields are name, memberno, Level and IsGoldMember flag. We&#8217;re now gonna create a simple Gui for that.
What many developers do when faced to create a GUI for such a task is create a generic data entry form, kind of like this:

Cool, its pretty generic, I [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, say we have a member database.  Entity is &#8220;Member&#8221;, fields are name, memberno, Level and IsGoldMember flag. We&#8217;re now gonna create a simple Gui for that.</p>
<p>What many developers do when faced to create a GUI for such a task is create a generic data entry form, kind of like this:</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/gui0.png"><img class="alignnone size-medium wp-image-1008" title="gui0" src="http://aspcode.net/wp-content/uploads/2010/09/gui0-300x151.png" alt="" width="300" height="151" /></a></p>
<p>Cool, its pretty generic, I can use it for new/update with a simple flag, and thanks to me being so clever using EF4/NHibernate/insert any ORM here, everything is set. I feed it/bind some data and then when I call SaveChanges it will be in my database. 30 minutes, Done!</p>
<p>So, whats the problem with that approach? Well for starters, all we have talked about is data. We havn&#8217;t even talk about behaviour, meaning what should be able to do with data. In this case we want to just modify the &#8220;Level&#8221; and &#8220;Is gold member&#8221; flag.</p>
<p>&#8220;Ok no problem. I&#8217;ll add some ReadOnly = true;&#8221; and were done again&#8230;</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/gui2.png"><img class="alignnone size-medium wp-image-1009" title="gui2" src="http://aspcode.net/wp-content/uploads/2010/09/gui2-300x151.png" alt="" width="300" height="151" /></a></p>
<p>Ok. It seems like we have solved our problem. But, now lets say, a few months later the boss says, from next week we need to send an email to billing apartment when a member is being upgraded from Beginner to Intermediate.</p>
<p>And you say: &#8220;what, upgrade? Oh, you mean they change the &#8220;Level&#8221; field from Beginner to Intermediate. Now I see. &#8221; And off you go hitting Visual Studio again, coding it into the very same form.  In your Save button handler, if (oldlevel == &#8220;beginner&#8221; &amp;&amp; newlevel == &#8220;intermediate&#8221;) SendMessageToBilling&#8230;</p>
<p>I bet you already see what&#8217;s coming. Is there a risk of email being sent which shouldn&#8217;t?  Since all we have is CRUD (modify data) we face the risk of having other level changes (such as pure error corrections) being treated as &#8220;upgrades&#8221;.  Someone might have done an error when registering. Does that happen? Well, in most systems every day more or less. Bottom line: In our GUI there is no distinction between corrections and upgrades.</p>
<p>Ok, the example might be very madeup, but the trouble with CRUD system is having double meaning for the same &#8220;Save&#8221; button .  And these types of all-in-one-data-entry CRUD forms surely invites to these types of errors. And I am not talking about programming errors here, I am talking about real business problems.</p>
<p>If we instead go back to &#8220;what should be able to do&#8221; and behaviour, we start by asking &#8220;What are we supposed to do&#8221;?  And we might get answers like: We want to be able to upgrade a user from Beginner to Intermediate level, or Expert level, and when that happen an email should be sent to billing.</p>
<p>And that type of dialog should be the base for our GUI:</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/gui1.png"><img class="alignnone size-medium wp-image-1010" title="gui1" src="http://aspcode.net/wp-content/uploads/2010/09/gui1-300x151.png" alt="" width="300" height="151" /></a></p>
<p>This makes the GUI much clearer, as in letting the user KNOW what the effects will be.  Now in our code we have clearly distinct executions paths for these veru different use cases.</p>
<p>Now where do the bashing on ORMS (&#8220;so clever using EF4/NHibernate/insert any ORM here&#8221;) come in?</p>
<p>That&#8217;s the next step. Instead of storing &#8220;current state&#8221; in our database, what about storing all statechanges instead. Causel GUI is one thing, when using an ORM we still leave it to the UOW of our ORM to keep track of changes &#8211; and it will simply calculate the delta (changes) and store what it need to store, so the end result in our database is still the SAME in our better GUI as in the first one.</p>
<p>All in all, so far with out &#8220;clear user intention GUI &#8221; we havn&#8217;t won much I guess&#8230; Therefore, for tracing, and most important for business reasons &#8211; wouldn&#8217;t it be great to save be able to save ALL changes done. This way we get a log like</p>
<p>2009-12-01 LevelCorrected from a to b</p>
<p>2009-12-09 LevelUpgraded from b to c</p>
<p>That&#8217;s the nest article &#8211; as we get into saving events.</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/no-crud-allow-for-saving-user-intent-in-your-gui/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CQRS flowchart</title>
		<link>http://aspcode.net/cqrs-flowchart</link>
		<comments>http://aspcode.net/cqrs-flowchart#comments</comments>
		<pubDate>Wed, 01 Sep 2010 08:37:32 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=999</guid>
		<description><![CDATA[In my previous more technical post about switching serialization technique I talk about me needing to run a conversion in two steps to change 1500000 events in my database from one format to another.
That scenario by itself might not be very common (it simply shouldn&#8217;t, but I am at early stages in my CQRS exploration, [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous more technical post about <a href="http://aspcode.net/using-json-as-intermediate-when-switching-binary-serialization-technique">switching serialization technique</a> I talk about me needing to run a conversion in two steps to change 1500000 events in my database from one format to another.</p>
<p>That scenario by itself might not be very common (it simply shouldn&#8217;t, but I am at early stages in my CQRS exploration, hence my decision to change a pretty technical aspect ).</p>
<p>Put that aside, the beauty of CQRS is it allows you to do application upgrades etc, typically just putting a new version in production &#8211; WHILE USERS STILL ARE USING IT.</p>
<p>CQRS could very well be the end of, &#8220;oh, I need to stay at work til late when all users have logged out to upgrade the system&#8221;.  To be honest CQRS by itself is not the answer, a loosly coupled architechture is (and it could be achieved by other means than adopting CQRS), but in my point of view CQRS really drives you (the developer) to  loosly coupled architechturing.</p>
<p>Here is a flowchart (click on it to see full size):</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture4.png"><img class="alignnone size-medium wp-image-1000" title="CropperCapture[4]" src="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture4-273x300.png" alt="" width="273" height="300" /></a></p>
<p>By utilizing persistant queues, and of course adopting the thinking of eventual consistancy, you could very well take down the &#8220;Business Logic&#8221; process (commandhandler) while your users keeps using the client &#8211; upgrade it, and start it up again. And it will start processing commands where it left off.</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/cqrs-flowchart/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JSon as intermediate when switching binary serialization technique</title>
		<link>http://aspcode.net/using-json-as-intermediate-when-switching-binary-serialization-technique</link>
		<comments>http://aspcode.net/using-json-as-intermediate-when-switching-binary-serialization-technique#comments</comments>
		<pubDate>Wed, 01 Sep 2010 07:36:14 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=994</guid>
		<description><![CDATA[Background: For some reasons I chose certain architechture for storing binary representations of my objects
I had a base class
[code language="C#"]
EventBase
Guid AggregateId
DateTime Created
int SequenceNo
[/code]
My applications &#8220;events&#8221; inherited from this base class like
[code language="C#"]
public class ProjectActivatedEvent : EventBase, ICustomBinarySerializable
{
public ProjectActivatedEvent(Guid aggid, bool active)
: base(aggid, DateTime.Now)
{
Active = active;
}
public bool Active { get; set; }
[/code]
For storage of serialized data [...]]]></description>
			<content:encoded><![CDATA[<p>Background: For some reasons I chose certain architechture for storing binary representations of my objects</p>
<p>I had a base class<br />
[code language="C#"]<br />
EventBase<br />
Guid AggregateId<br />
DateTime Created<br />
int SequenceNo<br />
[/code]</p>
<p>My applications &#8220;events&#8221; inherited from this base class like<br />
[code language="C#"]<br />
public class ProjectActivatedEvent : EventBase, ICustomBinarySerializable<br />
{<br />
public ProjectActivatedEvent(Guid aggid, bool active)<br />
: base(aggid, DateTime.Now)<br />
{<br />
Active = active;<br />
}<br />
public bool Active { get; set; }</p>
<p>[/code]</p>
<p>For storage of serialized data I used a SQL Server table (eventstore)</p>
<p><a href="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture15.png"><img class="alignnone size-full wp-image-997" title="CropperCapture[15]" src="http://aspcode.net/wp-content/uploads/2010/09/CropperCapture15.png" alt="" width="294" height="182" /></a></p>
<p>and serialized using <a href="http://codebetter.com/blogs/gregyoung/archive/2008/08/24/fast-serialization.aspx">Greg Youngs fast serializer</a> (ICustomBinarySerializable) since its really fast and effective</p>
<p>My serialization code looked like<br />
[code language="C#"]<br />
public void WriteDataTo(SerializationWriter writer)<br />
{<br />
base.WriteDataToBase(writer);<br />
writer.Write(Active);<br />
}</p>
<p>public void SetDataFrom(SerializationReader reader)<br />
{<br />
base.SetDataFromBase(reader);<br />
Active = reader.ReadBoolean();<br />
}</p>
<p>[/code]</p>
<p>Now I wanted to do a major rearchitecturing of my code.</p>
<p>For starters, get rid of EventBase and introduce a Interface IEvent instead which all events inherits from.<br />
Second: Use protobuf-net instead.</p>
<p>Basically:</p>
<p>[code language="C#"]</p>
<p>[ProtoContract]<br />
public class ProjectActivatedEvent : IEvent<br />
{<br />
public ProjectActivatedEvent()<br />
{</p>
<p>}</p>
<p>public ProjectActivatedEvent(Guid aggid, bool active)<br />
{<br />
AggregateId = aggid;<br />
Created = DateTime.Now;</p>
<p>Active = active;<br />
}<br />
[ProtoMember(10)] public bool Active { get; set; }</p>
<p>//IEvent<br />
[ProtoMember(1)] public Guid AggregateId { get; set; }<br />
[ProtoMember(2)] public int SequenceNo { get; set; }<br />
[ProtoMember(3)] public DateTime Created { get; set; }<br />
//</p>
<p>}</p>
<p>[/code]<br />
And there I was. I had two branches of my sourcecode, one the old way, one with the new way. Tests shows everything is working ok.<br />
How can I now convert the (1500000) existing records in table eventstore to the new format?</p>
<p>The solution was to introduce JSon into the equation. So (using my old branch) I coded a app which loops all (old style) events, possible since the old code branch knows how to deserialize them of course,  and converts them to JSon. Storing them into a intermediate table.</p>
<p>Second: from the new code branch I simple coded a new app which deserialized the JSon (into my new classes), and stored them the<br />
Protobuf way.</p>
<p>The beauty of JSon (de)serializer is that it simply works on field names. I did not change the names of my fields so<br />
it was therefore possible to use it as a pretty effective intermediate storage.</p>
<p>It did take some time running these loops but at least it worked.</p>
<p>I hope to present some more articles on this (and related) matters but want to show you the the trick to make a generic<br />
(de) serializer out of Json without the need to specify the type:<br />
[code language="C#"]<br />
class Json<br />
{<br />
static JsonSerializerSettings jsonSerializerSettings =<br />
new JsonSerializerSettings<br />
{<br />
DefaultValueHandling = DefaultValueHandling.Ignore,<br />
NullValueHandling = NullValueHandling.Ignore,<br />
MissingMemberHandling = MissingMemberHandling.Ignore,<br />
TypeNameHandling = TypeNameHandling.Objects<br />
};<br />
public static string Serialize(object theObject)<br />
{</p>
<p>return JsonConvert.SerializeObject(theObject, Newtonsoft.Json.Formatting.Indented, jsonSerializerSettings);<br />
}<br />
public static TType Deserialize(string sInData)<br />
{<br />
return (TType)JsonConvert.DeserializeObject(sInData, typeof(TType), jsonSerializerSettings);<br />
}<br />
}</p>
<p>[/code]<br />
The secret is TypeNameHandling.Objects. This adds a &#8220;$type:&lt;typename&gt;&#8221; in front of the JSon when serializing and<br />
therefore it is able to create such an object when deserializing.<br />
I still do have a TType, can&#8217;t remember why, since I stole thew code from an old project I made years ago, but the<br />
point is you can send in Object or a baseclass as type.</p>
<p>I deserialize my data like:<br />
Eventing.IEvent ev2 = Json.Deserialize&lt;Eventing.IEvent&gt;(row["data"].ToString());</p>
<p>And serialization was like<br />
Eventing.EventBase b = &#8230;<br />
string sa = Json.Serialize(b);</p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/using-json-as-intermediate-when-switching-binary-serialization-technique/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why use a ServiceBus in your .NET applications</title>
		<link>http://aspcode.net/why-use-a-servicebus-in-your-net-applications</link>
		<comments>http://aspcode.net/why-use-a-servicebus-in-your-net-applications#comments</comments>
		<pubDate>Fri, 13 Aug 2010 06:37:26 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=992</guid>
		<description><![CDATA[So I am currently evaluating the three major (open source) servicebuses for .NET, namely nServiceBus, Rhino Bus and MassTransit. I will (soon) come back with a post on what the outcome was (specific for me, but nonetheless).
But first I thought I&#8217;d start with explaining why I feel I need a servicebus (at all) as doing [...]]]></description>
			<content:encoded><![CDATA[<p>So I am currently evaluating the three major (open source) servicebuses for .NET, namely <a href="http://www.nservicebus.com/">nServiceBus</a>, <a href="http://hibernatingrhinos.com/open-source/rhino-service-bus">Rhino Bus</a> and <a href="http://masstransit-project.com">MassTransit</a>. I will (soon) come back with a post on what the outcome was (specific for me, but nonetheless).</p>
<p>But first I thought I&#8217;d start with explaining why I feel I need a servicebus (at all) as doing that might show some light of what it&#8217;s good for, it might help you decide if thats suitable for you as well.</p>
<p>First ask yourself if your application is distributed at all. Even if it isn&#8217;t (for example I have a lot of plain client/server oldschool apps which are nothing but client app and database server) &#8211; it might gain some my making it distributed. I wont get into all the reasons why such a decision could be beneficial, as thats nothing I can say something about, but in general if you centralize your applications core code your making it available for other  type of clients, like web. Also scaling (out, not up) gets easier.</p>
<p>It might also be that you want asynchronous commands, where you delegate actions such as &#8220;Send this email to this person&#8221; I dont have time to do it cause I am calculating this very valuable rate or whatever right now. This also gives you the effect of a clear architechture where you split different things up.</p>
<p><strong>A servicebus abstracts messaging and transports<br />
</strong></p>
<p>What do I mean by that? First of all, a message could be seen as a serialized command.  Say I sant to send that command &#8220;Send this email to this person&#8221;. Then a message must be delivered to that service. Typically you setup (in configfile) the different endpoints (servers) you want to talk with and do something like bus.Send(new EmailCommand(&#8230;)) .</p>
<p>A servicebus also abstracts HOW the messages are being delivered. Do we want to use MSMQ or ActiveMQ? Thats also configurable &#8211; and typically also possible to extend (plugin) more transports.</p>
<p><strong>A servicebus helps you with client AND server development</strong></p>
<p>Above we looked at how the client programming becomes really easy. A servicebus should also help you with programming the server part (in our example the email service). It should be configurable the same way as the client. It should in short handle all the transport details, and even more it should allow you to just write the business logic for each command (type of message), not much else. No plumbing code.</p>
<p><strong>A servicebus decouples messaging</strong></p>
<p>Fire and forget. Just like delegation of work to a collegue. We should be able to Send the message. And go back to the more important things we were doing.</p>
<p><strong>A servicebus should help setup pub/sub</strong></p>
<p>Apart from the fact that transports are pluggable, you would still benefit from a bus even if you have a plicy to just use a single transport, like say MSMQ &#8211; or WCF for that part. Instead of programming directly against it, when you use a servicebus you gain the benefit of some nice message distribution scenarios. The bus lets you setup and handle publisher/subscriber scenarios, where you might have multiple listeners (servers) for a certain message.</p>
<p><strong> </strong></p>
<p><strong>A servicebus should help setup sagas</strong></p>
<p>A saga is a serie of commands. Like a workflow. I wont get into this right now, but this is also a thing you wont get out of the box from the MSMQ api.</p>
<p><strong>A servicebus goes well into CQRS scheme</strong></p>
<p>I am now developing all my apps the CQRS way. The benefits and reasons for that is out of scope for this article</p>
<p><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/why-use-a-servicebus-in-your-net-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS sample app</title>
		<link>http://aspcode.net/cqrs-sample-app</link>
		<comments>http://aspcode.net/cqrs-sample-app#comments</comments>
		<pubDate>Wed, 21 Jul 2010 14:48:54 +0000</pubDate>
		<dc:creator>Stefan Holmberg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://aspcode.net/?p=988</guid>
		<description><![CDATA[So this summer I really try to update myself and my coding skills. Next on the list is CQRS.
I attended a Greg Young session at NDC in Oslo and really had a feeling, thats the way applications should be developed. Its been a long time since I had that feeling, I have been comfortably developing [...]]]></description>
			<content:encoded><![CDATA[<p>So this summer I really try to update myself and my coding skills. Next on the list is CQRS.</p>
<p>I attended a Greg Young session at NDC in Oslo and really had a feeling, thats the way applications should be developed. Its been a long time since I had that feeling, I have been comfortably developing my apps basically the same way for the last 8 years or so this is not only refreshing but also a lot of fun, me being the tech nerd I am&#8230;</p>
<p>So for about a month or so I have been trying to get a POC CQRS app up and running. Using nServiceBus and MSMQ as transport.</p>
<p>The whole experience (far from finished) can be read and full source can be downloaded from the <a href="http://cqrs.aspcode.net">CQRS NServiceBus example site</a></p>
]]></content:encoded>
			<wfw:commentRss>http://aspcode.net/cqrs-sample-app/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
