<?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: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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Simon says... architecture! » DDDSample</title>
	
	<link>http://simon-says-architecture.com</link>
	<description>Szymon Pobiega about software engineering and architecture</description>
	<lastBuildDate>Tue, 14 Feb 2012 06:07:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/dddsamplenet" /><feedburner:info uri="dddsamplenet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Classic DDD example, renewed</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/b3b86rq0sLg/</link>
		<comments>http://simon-says-architecture.com/2011/10/25/classic-ddd-example-renewed/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 18:36:14 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=852</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>I&#8217;ve spent some time recently renewing my old DDDSample.NET project. I understand that it is the projection of my subjective and uninformed view of Domain-Driven Design, but still I see a value in having some implementation compared to having nothing &#8212; it provokes discussion. That&#8217;s why I will continue to invest my time in it. [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>I&#8217;ve spent some time recently renewing my old <a href="https://github.com/SzymonPobiega/DDDSample.Net">DDDSample.NET</a> project. I understand that it is the projection of my subjective and uninformed view of Domain-Driven Design, but still I see a value in having <em>some</em> implementation compared to having nothing &#8212; it provokes discussion. That&#8217;s why I will continue to invest my time in it. If you happen to read this and want to take a look at the code, please remember that is is a <em>sample </em>(as the name suggests), not a <em>guidance</em>. The difference is following: a <em>sample</em> shows how <em>I</em> am doing things while a <em>guidance</em> would show how <em>you</em> are supposed to do things.</p>
<h3>Journey through the stack trace</h3>
<p>Classic version of DDDSample is a web application with simple UI created with ASP.NET MVC. This is where all starts. I would like to take you on a journey through the stack trace to explain various architectural decisions. Let&#8217;s register a new handling event.</p>
<h4>NHibernateAmbientSessionManager</h4>
<p>The very first class that gets a chance to process the request is <code class="syntaxhighlighter plain" style="display: inline;">NHibernateAmbientSessionManager</code>. It is responsible for creating an ambient NHibernate session that will be bound to the request. After processing the request the session is released. It can be accessed anywhere in the code statically through <code class="syntaxhighlighter plain" style="display: inline;">CurrentSessionContext</code> class. This is a built-in feature of NHibernate.</p>
<pre class="brush: csharp; title: ; notranslate">
public void CreateAndBind()
{
    CurrentSessionContext.Bind(_sessionFactory.OpenSession());
}
public void UnbindAndDispose()
{
    var session = CurrentSessionContext.Unbind(_sessionFactory);
    if (session != null)
    {
        session.Dispose();
    }
}
</pre>
<h4>HandlingController</h4>
<p>Next is the <code class="syntaxhighlighter plain" style="display: inline;">HandlingController</code> and it&#8217;s <code class="syntaxhighlighter plain" style="display: inline;">RegisterHandlingEvent</code> method/action</p>
<pre class="brush: csharp; title: ; notranslate">
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult RegisterHandlingEvent(string trackingId, DateTime? completionTime, string location, HandlingEventType type)
{
    if (!completionTime.HasValue)
    {
        ViewData.ModelState.AddModelError(&quot;completionTime&quot;, @&quot;Event completion date is required and must be a valid date.&quot;);
    }
    if (!ViewData.ModelState.IsValid)
    {
        AddHandlingLocations();
        AddHandlingEventTypes();
        return View();
    }
    _handlingEventFacade.RegisterHandlingEvent(completionTime.Value, trackingId, location, type);
    return RedirectToAction(&quot;Track&quot;, &quot;Tracking&quot;, new { trackingId });
}
</pre>
<p>There&#8217;s nothing fancy here, but is shows in a nice way that in this design,<strong> the responsibility of a controller is data validation and parsing</strong> (mostly done by MVC internals). After ensuring that data conforms to the required format, it is passed to another class which is&#8230;</p>
<h4>HandlingFacade</h4>
<p>This class hides the design of internals of the application from the UI. As far as controllers are concerned, business logic is implemented in façade&#8217;s methods. The truth is slightly different, however.</p>
<pre class="brush: csharp; title: ; notranslate">
public void RegisterHandlingEvent(DateTime completionTime, string trackingId, string location, HandlingEventType type)
{
    var command = new RegisterHandlingEventCommand
                        {
                            CompletionTime = completionTime,
                            TrackingId = trackingId,
                            OccuranceLocation = location,
                            Type = type
                        };
    _pipelineFactory.Process(command);
}
</pre>
<p>All the façade is doing is packing the arguments into a command object and sending this command to the pipeline where it is processed. Why create a separate class instead of putting this method on the controller? I like my controllers to be concerned only by the UI and have only one reason to change.</p>
<h4>NHibernateTransactionCommandFilter</h4>
<p>Before the command is actually executed, a number of filters are invoked. I use a very simple <a href="https://github.com/SzymonPobiega/LeanCommandUnframework">command pattern</a> implementation I&#8217;ve written a few weeks ago for the sole purpose of using in DDDSample. It allows me to define these filters in a nice (again, subjective view) way</p>
<pre class="brush: csharp; title: ; notranslate">
public void OnHandling(object command)
{
    _ambientSession = CurrentSessionContext.Unbind(_sessionFactory);
    _session = _sessionFactory.OpenSession();
    _transaction = _session.BeginTransaction();
    CurrentSessionContext.Bind(_session);
}
public void OnHandled(object command, object result)
{
    CurrentSessionContext.Unbind(_sessionFactory);
    _transaction.Commit();
    _session.Close();
    CurrentSessionContext.Bind(_ambientSession);
}
</pre>
<p>Before handling a command an aforementioned ambient NHibernate session is unbound from the current context. We are not going to use it while processing the command because we need a clear workplace. We open a new session and a a new transaction. <strong>Whatever happens in the command handler, stays in the command handler</strong>. After a command succeeds we unbind the session it used and commit the transaction. Then we restore the ambient session so that UI can use it.</p>
<p>Why don&#8217;t we just use a transaction on this ambient session? There is a couple of reasons. First, there can be a transaction started before processing the command and we don&#8217;t want to take part in it. Second, we want to be absolutely sure we don&#8217;t have any entities in the session-level cache. Why? Because we might use some hints to fetch them more efficiently in context of command processing (like for example force eager load on some relations). And last but not least, if command fails we don&#8217;t want to break the session UI was using because it may need it for whatever reason after the command processing attempt failed.</p>
<p>The corollary of this is, <strong>we don&#8217;t want to put any persistent (tracked by NHibernate) into the command</strong>. If we allowed this, we could attach it by mistake to this other session and very strange things could happen. The side effect is we can safely serialize commands which allows us, if the need comes, to put our domain model on a separate tier then its client (the web application).</p>
<h4>RegisterHandlingEventCommandHandler</h4>
<p>When we have the new session and transaction in place it&#8217;s time to do the actual work. Here&#8217;s how a typical command handler look like</p>
<pre class="brush: csharp; title: ; notranslate">
public object Handle(RegisterHandlingEventCommand command)
{
    var trackingId = new TrackingId(command.TrackingId);
    var cargo = _cargoRepository.Find(trackingId);
    var occuranceLocationUnLocode = new UnLocode(command.OccuranceLocation);
    var occuranceLocation = _locationRepository.Find(occuranceLocationUnLocode);
    var evnt = new HandlingEvent(command.Type, occuranceLocation, DateTime.Now, command.CompletionTime, cargo);
    _handlingEventRepository.Store(evnt);
    return null;
}
</pre>
<p>The idea here is to have only one method or constructor invocation on an <em>Aggregate Root</em> in one command. As you can see, command handler&#8217;s responsibility is to convert the raw data from the command to the proper <em>Value Objects</em>. The validation of data is performed when constructing VOs. In this case we create a new AR so we first instantiate a new object and then call repository to store it.</p>
<h4>HandlingEventRepository</h4>
<p>What happens in the repository?</p>
<pre class="brush: csharp; title: ; notranslate">
public void Store(HandlingEvent handlingEvent)
{
    Session.Save(handlingEvent);
    _eventPublisher.Raise(handlingEvent);
}
</pre>
<p>Two things. First, we save the newly created AR to the command&#8217;s session. Then we use an <em>Event Aggregator</em> to publish this AR as an event. I based this approach on Eric Evans&#8217; <a href="http://domaindrivendesign.org/library/evans_2009_1">What I&#8217;ve learned about DDD since the book</a> presentation where he explains that in many domains you encounter <em>Aggregate Roots</em> that are immutable. He calls them <em>Events.</em></p>
<h4>CargoWasHandlerEventHandler</h4>
<p>The <em>Event Aggregator</em> publishes the event to all interested parties. In our case there is only one</p>
<pre class="brush: csharp; title: ; notranslate">
public void Handle(HandlingEvent handlingEvent)
{
    handlingEvent.Cargo.DeriveDeliveryProgress(handlingEvent);
}
</pre>
<p>It calls a method on a Cargo <em>Aggregate Root</em> to notify it about the event. One thing worth notice here is we are doing it synchronously in the sample but our contract does not guarantee synchronicity. We write our event handlers in such a way that they can be executed asynchronously to the transaction that published the event. It is good to have such possibilities open in case we need to scale.</p>
<h4>Cargo</h4>
<p>This is how we reach the Cargo AR</p>
<pre class="brush: csharp; title: ; notranslate">
public virtual void DeriveDeliveryProgress(HandlingEvent lastHandlingEvent)
{
    Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, lastHandlingEvent);
}
</pre>
<p>The method looks very simple and it is not a coincidence. In classic DDD we have limited testing options since we can&#8217;t set our <em>Entities</em> to proper state easily (as easy in if we use <em>Event Sourcing</em>). That&#8217;s why we don&#8217;t want to test <em>Entities</em>. We want to test <em>Value Objects </em>because they are immutable and truly persistence ignorant. All we do in an <em>Entity</em> is pass the arguments to a VO and replace the current value with a new one. The probability that we make a bug in this one-liner is small, at least I hope so.</p>
<h4>Delivery</h4>
<p>Finally we arrived at our destination, the <em>Value Object. </em>Here I won&#8217;t include any code as it is quite complex and lengthy. I&#8217;ve already said probably the most important thing about VOs in this approach: <strong>they are immutable</strong>. This property allows us to test them easily. The compromise we are willing to accept in regards to <em>Value Objects</em> is, we expose their state via properties. Because we don&#8217;t have <em>Command and Query Responsibility Separation</em>, we use same objects (but remember, fetched via different session) to read and to write.</p>
<h3>Summary</h3>
<p>I hope you enjoyed this journey through the <a href="http://jeffreypalermo.com/blog/the-onion-architecture-part-1/">layers of the onio</a>n. Remember that this is just a sample. Most of its features were tested in the field but some combinations of them were not. I am eager to hear what you think about this approach and also to hear about your approach to DDD when size and/or complexity does not justify CQRS.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2011/10/25/classic-ddd-example-renewed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2011/10/25/classic-ddd-example-renewed/</feedburner:origLink></item>
		<item>
		<title>Renewing DDDSample.Net, iteration 0</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/5SItramLK1Y/</link>
		<comments>http://simon-says-architecture.com/2011/09/27/renewing-dddsample/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 05:35:50 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=844</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>As I promised in one of the previous posts, I am now in process of renewing the DDDSample.Net source code. It&#8217;s been quite a while since I published the first version of it. Many technologies have changed and my take on Domain-Driven Design and software architecture also has changed slightly.
First of all, the repo was [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>As I promised in <a href="http://simon-says-architecture.com/2011/09/08/net-architecture-samples">one of the previous posts</a>, I am now in process of renewing the DDDSample.Net source code. It&#8217;s been quite a while since I published the first version of it. Many technologies have changed and my take on Domain-Driven Design and software architecture also has changed slightly.</p>
<p>First of all, the repo was moved to <a href="https://github.com/SzymonPobiega/DDDSample.Net">github</a>. Hurray! In the process of transforming TFS repository into a git one I lost the branch structure. Originally all versions were branched one from another which made updating all samples a little bit easier since (ideally) I had to change only one and then merge this change. With git I am thinking of a slightly different structure. I am pretty sure I can freeze some portions of the solution (like routing engine and most of the UI) and move them to separate repos. Then I can import them as submodules to each of the samples.</p>
<p>At first I just wanted to add new features to the existing samples but when I opened the vanilla version (a port of Java <a href="http://dddsample.sourceforge.net/">DDDSample</a>) I found out that it is so outdated that it urgently needs to be renewed. The changes I made so far include:</p>
<ul>
<li>Upgrading solution to VS2010 format</li>
<li>Removing the web setup project (I guess nobody used it, ever)</li>
<li>Switching to NuGet for resolving most of the packages (using <em>don&#8217;t commit packages</em> workflow described <a href="http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html?spref=tw">here</a> by David Ebbo)</li>
<li>Upgrading some dependencies (like NHibernate) to the newest versions</li>
<li>Switching from using façade-like classes in application layer to commands and command handlers implemented using brand new tiny LeanCommandUnframework (a separate micro project hosted <a href="https://github.com/SzymonPobiega/LeanCommandUnframework">here</a> on github)</li>
<li>Switching from Unity 1.2 to Autofac</li>
<li>Removing dependency on NServiceBus</li>
<li>Cleaning up the global.asax file</li>
</ul>
<p>I am now quite happy with the solution. Everything seems to have its place in the architecture. There are some things yet to be clean up such as changing the way command handlers are created but these should be minor fixes. If you have some spare time, please clone the repo and check if you like what I did. And please note that only <strong>Vanilla</strong> version was updated.</p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2011/09/27/renewing-dddsample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2011/09/27/renewing-dddsample/</feedburner:origLink></item>
		<item>
		<title>.NET architecture samples</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/7nRfU82Tuhc/</link>
		<comments>http://simon-says-architecture.com/2011/09/08/net-architecture-samples/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 05:08:56 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=832</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>A Domain-Driven Design sample I created some time ago, DDDSample.Net, is now a little bit rusty. I though it is a good idea to spend some time and make it up to date. It will involve, for sure, moving the project to github because you all know what I thing about TFS version control.
Currently there [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>A Domain-Driven Design sample I created some time ago, <a href="http://dddsamplenet.codeplex.com/">DDDSample.Net</a>, is now a little bit rusty. I though it is a good idea to spend some time and make it up to date. It will involve, for sure, moving the project to <a href="https://github.com/">github</a> because you all know what I thing about TFS version control.</p>
<p>Currently there are 4 major versions of DDDSample solution</p>
<ul>
<li>Vanilla (&#8216;by the book&#8217;)</li>
<li>CQRS with two relational databases</li>
<li>CQRS with event sourcing</li>
<li>Layered model</li>
</ul>
<p>I am thinking about dropping the second one as it was more like an experiment, not a final solution. The layered model is an advanced version of vanilla solution witch demonstrates how to structure larger domain models. Another thing I might do is migrate the event sourcing sample to <a href="http://ncqrs.org/">NCQRS</a>. Or maybe I should use <a href="https://github.com/joliver/EventStore">EventStore</a> directly? What do you think?</p>
<p>Now the important part. I have some ideas what to implement next and I need your feedback. Help me rate them</p>
<ul>
<li>Event driven SOA a&#8217;la Udi Dahan. This would be probably an extended version of layered model sample but with slightly different structuring approach (autonomous services instead of layers).</li>
<li>Vanilla with RavenDB as a data store</li>
<li>Native CQRS with event sourcing on RavenDB according to <a href="http://ayende.com/blog/4530/raven-event-sourcing">this description</a> by Ayende.</li>
</ul>
<p>If you have some other ideas, post them in the comments. I am also thinking about getting rid of the installer projects. It does not make sense to just install the application in IIS and don&#8217;t look at the code. And if you open it, you can run it by hitting F5.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2011/09/08/net-architecture-samples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2011/09/08/net-architecture-samples/</feedburner:origLink></item>
		<item>
		<title>DDDSample.Net news</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/te2uCvrNX0U/</link>
		<comments>http://simon-says-architecture.com/2010/05/05/dddsample-net-news/#comments</comments>
		<pubDate>Wed, 05 May 2010 03:59:59 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=623</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>Quite a lot have happened since last DDDSample.Net information was published here. Version 0.8 was released on April 18. This is the most recent binary release of the project. It focuses on the concept of model layers which were introduced in a separate code branch.
On April 30 another branch &#8212; AutoPersistence &#8211; was added. AutoPersistence [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>Quite a lot have happened since last DDDSample.Net information was published here. <a href="http://dddsamplenet.codeplex.com/releases/view/43833">Version 0.8</a> was released on April 18. This is the most recent binary release of the project. It focuses on the concept of <strong>model layers</strong> which were introduced in a separate code branch.</p>
<p>On April 30 another branch &#8212; AutoPersistence &#8211; was added. AutoPersistence is a concept-proof exploring the possibilities of <strong>inferring persistence mapping from the model</strong>. AP uses slightly modified version of FluentNHibernate to achieve this goal. This version is currently available only in trunk.</p>
<p>The most recent change is a redesign of Handling aggregate in Vanilla version of DDDSample. The new design is now more aligned with book and original Java-based project.</p>
<p>Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/05/05/dddsample-net-news/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/05/05/dddsample-net-news/</feedburner:origLink></item>
		<item>
		<title>Automatic domain model persistence – halfway through</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/h5smwmlt_5k/</link>
		<comments>http://simon-says-architecture.com/2010/04/30/fluentdomain-2/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 03:52:59 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[DDDSample]]></category>
		<category><![CDATA[FluentNHibernate]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=618</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>Just a quick note. There was no new post yesterday because I was busy implementing automatic persistence for domain model concept-proof. In the previous post I was writing about private field automapping. Since then I managed to implement a bunch of other concepts, including composite elements.
My fork of FluentNHibernate (automapping-fields branch) on github was updated with [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>Just a quick note. There was no new post yesterday because I was busy implementing automatic persistence for domain model concept-proof. In the previous post I was writing about private field automapping. Since then I managed to implement a bunch of other concepts, including composite elements.</p>
<p>My <a href="http://github.com/SzymonPobiega/fluent-nhibernate">fork of FluentNHibernate</a> (automapping-fields branch) on github was updated with the most current code version.</p>
<p>DDDSample.NET <a href="http://dddsamplenet.codeplex.com/SourceControl/changeset/view/46929#">&#8216;AutoPersistence&#8217; branch</a> uses the modified FNH to persists its domain model and it works! Without a single mapping file!</p>
<p>So, if everything works fine, why &#8216;halfway through&#8217;? That is because the code is very, very dirty and needs much work before it can be used in production.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/04/30/fluentdomain-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/04/30/fluentdomain-2/</feedburner:origLink></item>
		<item>
		<title>DDDSample 0.7</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/J8f46MnYii8/</link>
		<comments>http://simon-says-architecture.com/2010/03/25/dddsample-0-7/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 05:41:48 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=544</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>0.7 release of DDDSample is there. Go, download it, and say if you like it. There are now really five different versions in the package:

Classic with synchronous communication
Classic with asynchronous communication via NServiceBus (these two can be switched using compilation target)
CQRS using two NHibernate relational sores
CQRS using with relational store based on LINQ 2 SQL (not available [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>0.7 release of DDDSample is <a href="http://dddsamplenet.codeplex.com/releases/view/42247">there</a>. Go, download it, and say if you like it. There are now really five different versions in the package:</p>
<ul>
<li>Classic with synchronous communication</li>
<li>Classic with asynchronous communication via <a href="http://www.nservicebus.com/">NServiceBus</a> (these two can be switched using compilation target)</li>
<li>CQRS using two NHibernate relational sores</li>
<li>CQRS using with relational store based on LINQ 2 SQL (not available as binary installation package, only in trunk)</li>
<li>Event Sourcing with CQRS</li>
</ul>
<p>I really would like to hear you opinions on where the project should go now? Do you think it is finished and contains all the things it should contains? What needs to be done? What should be done first?</p>
<p>Installation is dead-simple when using default SQLite database, so don&#8217;t be afraid. If you have any problems, feel free to contact me via <a href="mailto:szymon@pobiega.com">e-mail</a> or <a href="http://twitter.com/SzymonPobiega">twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/03/25/dddsample-0-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/03/25/dddsample-0-7/</feedburner:origLink></item>
		<item>
		<title>Raportowanie a CQRS</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/E_jTS5T58sU/</link>
		<comments>http://simon-says-architecture.com/2010/03/11/raportowanie-a-cqrs/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 06:20:41 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Notki po polsku]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=495</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/pl.png" width="17" height="17" alt="" title="Notki po polsku" /><br/>Zdaję sobie sprawę, że tytuł jest ogromnym skrótem myślowym. Tak naprawdę chodzi mi o możliwość generowania raportów z rozwiązań wykorzystujących model domeny z CQRS. Oczywiście, posłużę się przykładem DDDSample. Na wstępnie jednak muszę się przyznać, że nie jestem ekspertem od business intelligence, więc jeśli popełniłem jakieś karygodne wykroczenia, proszę o wyrozumiałość i zgłoszenie poprawek w [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/pl.png" width="17" height="17" alt="" title="Notki po polsku" /><br/><p>Zdaję sobie sprawę, że tytuł jest ogromnym skrótem myślowym. Tak naprawdę chodzi mi o możliwość generowania raportów z rozwiązań wykorzystujących <strong>model domeny</strong> z CQRS. Oczywiście, posłużę się przykładem DDDSample. Na wstępnie jednak muszę się przyznać, że nie jestem ekspertem od <em>business intelligence</em>, więc jeśli popełniłem jakieś karygodne wykroczenia, proszę o wyrozumiałość i zgłoszenie poprawek w komentarzach &#8212; będę wdzięczny za wszelkie uwagi.</p>
<p>Problem wygląda następująco: nasz system transakcyjny działa świetnie, jest wydajny, bezpieczny itp. Nadszedł jednak czas, aby wygenerować z niego jakiś raport potwierdzający, że system się sprawdza biznesowo. Jak to zrobić, mając po stronie komend <strong>silnie znormalizowaną</strong> bazę zoptymalizowaną dla operacji update/insert, a po stronie zapytań &#8212; <strong>tabele odzwierciedlające formatki</strong> UI? Są dwie możliwości:</p>
<ol>
<li><strong>Zmodyfikować bazę strony zapytań, aby stała się prawdziwą &#8220;bazą raportową&#8221;.</strong> Dzięki temu będzie mogła służyć i do generowania raportów i do wyświetlania danych na formatki. Niestety konsekwencją tego jest znaczne zwiększenie skomplikowania kodu dostępu do danych dla formularzy i list. Dlaczego? Zaraz zobaczymy.</li>
<li><strong>Dodać kolejną (3!) bazę danych zoptymalizowaną pod kątem raportów.</strong> Minusem jest, jak zwykle, zwiększony wysiłek ze strony administratorów. Plus (również jak zwykle): lepszy podział odpowiedzialności i możliwość optymalizacji.</li>
</ol>
<p>Spróbujmy więc zrealizować to drugie rozwiązanie. Na początek potrzebujemy struktury bazodanowej, która nadawałaby się do generowania raportów. Oczywiście, w rzeczywistej sytuacji zapytalibyśmy naszego klienta, jakich raportów potrzebuje. Niestety nie mam takiej możliwości pisząc te notkę. Przygotowałem więc schemat, który <strong>wydaje mi się użyteczny</strong>:</p>
<p><a href="http://simon-says-architecture.com/wp-content/uploads/2010/03/DDDReporting.png"><img class="size-full wp-image-497   alignnone" title="Schemat bazy danych" src="http://simon-says-architecture.com/wp-content/uploads/2010/03/DDDReporting.png" alt="" width="643" height="462" /></a></p>
<p>Pozwala on na analizę towarów pod kątem zmian rzeczywistej trasy w stosunku do tej zarejestrowanej i ich wpływu na dostarczenie towaru. Z drugiej strony umożliwia także analizę samych tras: którędy prowadziła, czy wynikiem było złe skierowanie towaru, czy została porzucona (zmieniona), czy też w wyniku jej realizacji towar został dostarczony.</p>
<p>Na pierwszy rzut oka widać, że transformacja tak przechowywanych danych do formatu niezbędnego do wyświetlenie na formatkach byłoby bardzo trudna. Utwierdza mnie to w przekonaniu, że (tym razem) słusznie wybrałem wariant drugi (osobne bazy).</p>
<p>Mając już strukturę danych, zastanówmy się, czego potrzebujemy, aby ją zasilić? Z pomocą przychodzi nam naturalna właściwość tego rodzaj systemów CQRS. Są one naturalnie przystosowane do scenariuszy <strong>real-time business intelligence</strong>, ponieważ posiadają wbudowany mechanizm wypychania danych z bazy transakcyjnej w czasie rzeczywistym (służący do zasilania bazy dla zapytań). Możemy się więc w niego bezwstydnie wpiąć. Potrzebujemy jedynie czterech obiektów obsługi komunikatów dla zdarzeń:</p>
<ul>
<li><strong>zarejestrowano towar</strong> (utworzenie obiektu w CargoFacts i RouteFacts)</li>
<li><strong>przypisano trasę</strong> (aktualizacja RouteFacts)</li>
<li><strong>zmieniono lokalizację docelową</strong> (utworzenie obiektu w RouteFacts, modyfikacja reprezentującego poprzednią trasę)</li>
<li><strong>zarejestrowano zdarzenie obsługi</strong> (aktualizacja rzeczywistego miejsca załadunku towaru i miejsca dostarczenia towaru, aktualizacja pola &#8220;misdirected&#8221; itp.)</li>
</ul>
<p>Implementacje możemy wykonać (znów) na dwa sposoby: albo bezpośrednio przygotowując odpowiednie komendy SQL, albo mapując przedstawiony model na obiekty. Co kto woli.</p>
<p>PS. Zamierzam spróbować zaimplementować przedstawione rozwiązanie. Jak tylko mi się uda, podzielę się z Wami wynikami eksperymentu.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/03/11/raportowanie-a-cqrs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/03/11/raportowanie-a-cqrs/</feedburner:origLink></item>
		<item>
		<title>DDDSample documentation update</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/r0m3WMMuhqA/</link>
		<comments>http://simon-says-architecture.com/2010/03/08/dddsample-documentation-update/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 20:05:52 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=490</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>I have just published some new documentation pages on DDDSample.Net CodePlex site. You can now read about Domain-Driven Design elements in context of class diagrams, compare CQRS approach to the classic one and read on how Event Sourcing influences the model.
]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>I have just published some <strong>new documentation</strong> pages on DDDSample.Net CodePlex site. You can now read about <a href="http://dddsamplenet.codeplex.com/wikipage?title=DDD%20building%20blocks%20in%20DDDSample.Net&amp;referringTitle=Documentation">Domain-Driven Design elements</a> in context of class diagrams, <a href="http://dddsamplenet.codeplex.com/wikipage?title=CQRS&amp;referringTitle=Documentation">compare CQRS approach</a> to the classic one and read on <a href="http://dddsamplenet.codeplex.com/wikipage?title=CQRS%20-%20Event%20Sourcing&amp;referringTitle=Documentation">how Event Sourcing influences</a> the model.</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/03/08/dddsample-documentation-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/03/08/dddsample-documentation-update/</feedburner:origLink></item>
		<item>
		<title>O usługach</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/_tfyrPwic1o/</link>
		<comments>http://simon-says-architecture.com/2010/03/01/o-uslugach/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 04:29:01 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Notki po polsku]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=464</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/pl.png" width="17" height="17" alt="" title="Notki po polsku" /><br/>Zostałem niedawno zapytany, dlaczego w projekcie DDDSample.NET projekt &#8220;Application&#8221; nazywa się właśnie tak, a nie &#8220;Domain Services&#8221;. Zwróciło to moją uwagę na całkiem spory problem nazewnictwa związanego z DDD oraz ogólnie z architekturami. Jednym ze źródeł problemu zdaje się być niesamowicie przeładowane znaczeniowo słowo &#8220;usługa&#8221;. Ale po kolei&#8230;
Wspomniany projekt &#8220;Application&#8221; zawiera fasadę Modelu Domeny udostępniającą [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/pl.png" width="17" height="17" alt="" title="Notki po polsku" /><br/><p>Zostałem niedawno zapytany, dlaczego w projekcie DDDSample.NET projekt &#8220;Application&#8221; nazywa się właśnie tak, a nie &#8220;Domain Services&#8221;. Zwróciło to moją uwagę na całkiem spory problem nazewnictwa związanego z DDD oraz ogólnie z architekturami. Jednym ze źródeł problemu zdaje się być niesamowicie przeładowane znaczeniowo słowo &#8220;usługa&#8221;. Ale po kolei&#8230;</p>
<p>Wspomniany projekt &#8220;Application&#8221; zawiera fasadę Modelu Domeny udostępniającą operacje biznesowe realizowane za pomocą tegoż modelu. Te operacje to coś w rodzaju <a href="http://martinfowler.com/eaaCatalog/transactionScript.html">transaction script</a>-ów operujących na obiektach domeny. Nazwę zaczerpnąłem oczywiście wprost z Java-owego oryginału, którego dokumentacja tak opisuje ten element architektury:</p>
<blockquote><p>The application layer is responsible for driving the workflow of the application, matching the use cases at hand. These operatios are interface-independent and can be both synchronous or message-driven. This layer is well suited for spanning transactions, high-level logging and security.</p>
<p>The application layer is thin in terms of domain logic &#8211; it merely coordinates the domain layer objects to perform the actual work.</p></blockquote>
<p>Przyznam szczerze, że nazwa &#8220;Application&#8221; nie jest najszczęśliwsza na świecie, bo tak na dobrą sprawę, nie mówi nic o przeznaczeniu tej warstwy. Można ją znaleźć także w innych przykładach, np. w <a href="http://jeffreypalermo.com/blog/the-onion-architecture-part-1/">architekturze cebulowej</a> Jeffreya Palermo. Różnica polega jednak na tym, że u Palermo nazwa brzmi &#8220;Application Services&#8221;, co niesie już ze sobą jakieś znaczenie &#8212; mamy do czynienia z usługami.</p>
<p>No właśnie. Dlaczego pisałem na wstępie, że winne jest słowo &#8220;usługa&#8221;? Ponieważ tak naprawdę ja najchętniej z &#8220;Application Services&#8221; zostawiłbym &#8220;Services&#8221; jako nazwę mojej warstwy. Zauważcie, że pasuje ona o wiele lepiej pasuje do przytoczonego opisu. Niestety usługi występują już w tylu kontekstach w naszej terminologii, że wprowadzenie kolejnych &#8220;usług&#8221; byłoby niewskazane.</p>
<p>Być może lepiej byłoby w ogóle zrezygnować z terminologii wywodzącej się z &#8220;Application Services&#8221;? Można się odwołać np. do tego, że warstwa ta implementuje przypadki użycia i nazwać ją &#8220;Use Cases&#8221;. Albo, podchodząc do problemu od strony technicznej, zauważyć że jest to implementacja wzorca fasady &#8212; &#8220;Model Facade&#8221;. A jak Wy nazywacie projekty takiego rodzaju w swoich architekturach?</p>
<p>Druga część pytania dotyczy <a href="http://dddstepbystep.com/wikis/ddd/domain-service.aspx">domain services</a> &#8212; usług modelu domeny. Wydaje się, że jest jeszcze wiele wątpliwości związanych z usługami w Domain Driven Design. Moje rozumienie tego termin jest następujące.</p>
<p>Usługi modelu domeny pozwalają wyrazić operacje, które nie mają naturalnie przypisanego obiektu wykonującego je lub są realizowane przez obiekty zewnętrzne w stosunku do modelu. Na przykład IPricingService to usługa zwracająca ceny produktów na podstawie danych uzyskanych z innego systemu za pośrednictwem webserwisu. Na poziomie modelu reprezentowana jest przez interfejs, aby nie uzależniać go od szczegółów implementacyjnych.</p>
<p>Osoba, która zadała mi pytanie rozumiała usługi domenowe jako sposób na wykonanie pewnych bardziej skomplikowanych operacji biznesowych poprzez orkiestrację wywołań na obiektach modelu, czyli&#8230; dokładnie to, co u mnie kryje znajduje się w warstwie &#8220;Application&#8221;. Podobne opinie znalazłem też na kilku znanych blogach, np. <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/21/services-in-domain-driven-design.aspx">tu</a>. Cóż, nie zgadzam się z takim podejściem. Nie widzę sensu, aby definiować takie byty. Co więcej, usługi domenowe w takim znaczeniu miałyby bardzo niebezpieczną tendencję to wysysania logiki biznesowej z obiektów modelu.</p>
<p>Podsumowując, w dużym skrócie i uproszczeniu:</p>
<ul>
<li>Następnym razem napewno nazwę swoją warstwę &#8220;Application&#8221; inaczej. Skłaniam się ku &#8220;Use Cases&#8221;.</li>
<li>Usługi domenowe mogą reprezentować albo operacje nie posiadające wykonawcy (algorytmy), albo być abstrakcją dla synchronicznych usług implementowanych na zewnątrz. Oba przypadki powinny być bardzo rzadkie.</li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">
<p>The application layer is responsible for driving the workflow of the application, matching the use cases at hand. These operatios are interface-independent and can be both synchronous or message-driven. This layer is well suited for spanning transactions, high-level logging and security.</p>
<p>The application layer is thin in terms of domain logic &#8211; it merely coordinates the domain layer objects to perform the actual work</p></div>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/03/01/o-uslugach/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/03/01/o-uslugach/</feedburner:origLink></item>
		<item>
		<title>Event sourcing in DDDSample: reviewing Mark Nijhof’s solution</title>
		<link>http://feedproxy.google.com/~r/dddsamplenet/~3/p7DFIvlFDnc/</link>
		<comments>http://simon-says-architecture.com/2010/02/25/event-sourcing-in-dddsample-reviewing-mark-nijhofs-solution/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 04:09:15 +0000</pubDate>
		<dc:creator>Szymon Pobiega</dc:creator>
				<category><![CDATA[Posts in English]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDDSample]]></category>

		<guid isPermaLink="false">http://simon-says-architecture.com/?p=447</guid>
		<description><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/>As CQRS version of DDDSample is getting mature, I am switching my development efforts to event sourcing support. For those of you who don&#8217;t know that yet, event sourcing is a pattern which encourages persisting not snapshots of data in particular moments in time, but rather events which describe how these data changes. Then, data [...]]]></description>
			<content:encoded><![CDATA[<img src="http://simon-says-architecture.com//wp-content/uploads/gb.png" width="17" height="17" alt="" title="Posts in English" /><br/><p>As CQRS version of DDDSample is getting mature, I am switching my development efforts to <strong>event sourcing</strong> support. For those of you who don&#8217;t know that yet, event sourcing is a pattern which encourages persisting not snapshots of data in particular moments in time, but rather events which describe how these data changes. Then, data snapshots (not only the latest, but also historic ones) can be reconstructed by applying these events starting from the &#8216;beginning of time&#8217;. More about defining event sourcing and CQRS can be found <a href="http://codebetter.com/blogs/gregyoung/archive/2010/02/16/cqrs-task-based-uis-event-sourcing-agh.aspx" target="_blank">here</a>.</p>
<p>I&#8217;ve started by looking at Marc Nijhof&#8217;s excellent series of posts (starting <a href="http://elegantcode.com/2009/11/11/cqrs-la-greg-young/" target="_blank">here</a>) describing event sourcing. Mark has built a sample application based on what he had learnt about CQRS during Greg Young&#8217;s course.</p>
<p>Mark&#8217;s solution is fairly simple. In the core there is a domain assembly containing classes that model domain concepts like Account and Client. These inherit and use additional infrastructure assemblies which provide event sourcing features.</p>
<p>One thing that looks odd to me is usage of <strong>memento pattern</strong> to store snapshots of aggregates. I don&#8217;t understand why can&#8217;t they (the aggregates) be simply serialized as they are. Maybe there is a reason behind this, but I don&#8217;t see it, at least for now. I marked this area for further investigation.</p>
<p>Moving away from the core, there are several supporting assemblies which contain commands, command handlers, events and so on. Personally, I don&#8217;t see a point in separating some of them. There is an obvious reason why commands and command handlers are in separate assemblies, but the events? They are part of the domain model, at least for me.</p>
<p>After more careful analysis I noticed that there is no notion of messages in Marks sample solution. The events themselves are passed from command side to query side. That is probably the reason why the events are defined in separate assembly &#8212; if they are to be used in reporting, it would be nice not to have to reference whole domain model assembly, only the events.</p>
<p>Going further, Mark is using a custom O/RMish solution to implement query/reporting side. I am not a big fan of custom solutions and I probably would use an off-the-shelve one, even if it is slightly more complex then necessary. I am planing to use NHibernate, as in the non-event-sourcing CQRS version.</p>
<p>Anyway, <strong>Mark did great job</strong> of describing event sourcing concepts to the public. I probably wouldn&#8217;t be able to start writing my own implementation in DDDSample without first reading his code. Thanks a lot!</p>
]]></content:encoded>
			<wfw:commentRss>http://simon-says-architecture.com/2010/02/25/event-sourcing-in-dddsample-reviewing-mark-nijhofs-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://simon-says-architecture.com/2010/02/25/event-sourcing-in-dddsample-reviewing-mark-nijhofs-solution/</feedburner:origLink></item>
	</channel>
</rss>

