<?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>Tigraine &#187; Castle</title>
	<atom:link href="http://www.tigraine.at/category/programmierung/net/castle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tigraine.at</link>
	<description>Daniel Hoelbling talks about .NET</description>
	<lastBuildDate>Mon, 06 Sep 2010 20:47:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Untangling the dependency ball! Windsor + NServiceBus + Caliburn + Fluent Nhibernate in one package</title>
		<link>http://www.tigraine.at/2010/09/06/untangling-the-dependency-ball-windsor-nservicebus-caliburn-fluent-nhibernate-in-one-package/</link>
		<comments>http://www.tigraine.at/2010/09/06/untangling-the-dependency-ball-windsor-nservicebus-caliburn-fluent-nhibernate-in-one-package/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 20:47:41 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2010/09/06/untangling-the-dependency-ball-windsor-nservicebus-caliburn-fluent-nhibernate-in-one-package/</guid>
		<description><![CDATA[
Unfortunately nu is still falling short on one thing: Making sure that all the stuff you install is actually compatible with the other stuff you have already installed. There is a ticket for this and I’m fairly confident this will get resolved (please vote the ticket up), but for now I was back to figuring [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tigraine.at/wp-content/uploads/2010/09/confusingroadsignlargewebview.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 10px 3px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="confusing-road-sign-large-web-view" border="0" alt="confusing-road-sign-large-web-view" src="http://www.tigraine.at/wp-content/uploads/2010/09/confusingroadsignlargewebview_thumb.jpg" width="211" height="244" /></a></p>
<p>Unfortunately <a href="http://www.tigraine.at/2010/08/25/the-fastest-way-to-install-dotless-nubular-nu/">nu</a> is still falling short on one thing: Making sure that all the stuff you install is actually compatible with the other stuff you have already installed. There is a <a href="http://github.com/nu/nu/issues/issue/13">ticket for this</a> and I’m fairly confident this will get resolved (please vote the ticket up), but for now I was back to figuring out what version of what framework to use to make my app compile.</p>
<p>As always, the main problem was Castle.Core, being present in 3 different versions. (NSB used version 1.1, Caliburn 1.2 and the latest Windsor release targets 2.5) </p>
<p>I decided to back down and use 1.2 since there is a NHibernate gem for 1.2 and a Windsor gem for 1.2. I’m now using NHibernate 3.0 alpha so think about using this “stack”. </p>
<p>Anyway, this is a collection of:</p>
<ol>
<li>NServiceBus 2.0 .NET 4 (2.0.0.1219)</li>
<li>NServiceBus.ObjectBuilder.CastleWindsor</li>
<li>Castle.Windsor (2.1)</li>
<li>Caliburn 2.0 (still unreleased from the trunk)</li>
<li>NHibernate 3.0.0.1002</li>
<li>FluentNhibernate 1.1 (Updated to NHibernate 3.0)</li>
<li>AutoMapper</li>
</ol>
<p>Disclaimer: The whole thing is built for .NET 4.0 and works on my machine. Don’t blame me if it’s broken for you.</p>
<p>Anyway. You can download the whole package of libraries here: <a href="http://www.tigraine.at/wp-content/uploads/2010/09/castle-stack.rar">castle-stack.rar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2010/09/06/untangling-the-dependency-ball-windsor-nservicebus-caliburn-fluent-nhibernate-in-one-package/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>Castle.Pagination v1.1.0 released</title>
		<link>http://www.tigraine.at/2009/12/05/castle-pagination-v1-1-0-released/</link>
		<comments>http://www.tigraine.at/2009/12/05/castle-pagination-v1-1-0-released/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 15:38:20 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/12/05/castle-pagination-v1-1-0-released/</guid>
		<description><![CDATA[Finally the Castle.Pagination component has reached v1.1.0 and is ready to be incorporated into the upcoming Castle Monorail 2.0 release. 
As for the changes: There are hardly any. Pagination is a solved problem and most of the code changes where bug fixes and minor improvements. 
Anyway, thanks Jonathan Rossi for helping me with the release! [...]]]></description>
			<content:encoded><![CDATA[<p>Finally the Castle.Pagination component has reached v1.1.0 and is ready to be incorporated into the upcoming Castle Monorail 2.0 release. </p>
<p>As for the changes: There are hardly any. Pagination is a solved problem and most of the code changes where bug fixes and minor improvements. </p>
<p>Anyway, thanks Jonathan Rossi for helping me with the release! I can’t wait for Castle to move to GitHub so we can finally put that whole “non-committer sends patches” misery behind us.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/12/05/castle-pagination-v1-1-0-released/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>It&#8217;s a kind of magic: MonoRail</title>
		<link>http://www.tigraine.at/2009/10/21/its-a-kind-of-magic-monorail/</link>
		<comments>http://www.tigraine.at/2009/10/21/its-a-kind-of-magic-monorail/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 09:57:46 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=782</guid>
		<description><![CDATA[I never cease to be amazed about Castle MonoRail, but this time I was really puzzled.     While working on a simple CRUD page I wrote code like this:


public void Unlock([ARFetch("id")] Member member)
{
&#160;&#160;&#160;&#160;PropertyBag["member"] = member;
}

public void Unlock([ARFetch("id")] Member member, DateTime expiration)
{
&#160;&#160;&#160;&#160;...


My view was then just a standard form, a textfield and a [...]]]></description>
			<content:encoded><![CDATA[<p>I never cease to be amazed about <a href="http://www.castleproject.org/monorail/index.html">Castle MonoRail</a>, but this time I was really puzzled.     <br />While working on a simple CRUD page I wrote code like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:fca376f0-1f33-43c1-a004-5bdd05cb2a7b" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public void Unlock([ARFetch("id")] Member member)
{
&#160;&#160;&#160;&#160;PropertyBag["member"] = member;
}

public void Unlock([ARFetch("id")] Member member, DateTime expiration)
{
&#160;&#160;&#160;&#160;...
</pre>
</div>
<p>My view was then just a standard form, a textfield and a submit button. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:4c3ce84b-b357-4c54-822f-e5d9895a74d6" class="wlWriterEditableSmartContent">
<pre name="code" class="xml">
&lt;form action="" method="POST"&gt;
&#160;&#160;&#160;&#160;&lt;ul&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;li&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$FormHelper.LabelFor("expiration", "Account expiration date")
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$FormHelper.TextFieldValue("expiration", "29.01.2010")
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;/li&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;li&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;input type="submit" value="Unlock" /&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;/li&gt;
&#160;&#160;&#160;&#160;&lt;/ul&gt;
&lt;/form&gt;
</pre>
</div>
<p>And, you may have guessed it, I forgot to put a hidden field with the UserId in there somewhere!<br />
  <br />Yes, I know – what a common mistake and what a bad one at that. But, and that’s the scary part. <em>It worked still</em>! I checked and re-checked, there is no Id anywhere passed as a result of the form submit, yet MonoRail somehow gets the Id from my previous call and works with that. </p>
<p>I couldn’t find the code inside MonoRail responsible for this behavior, and it seems only to work with Post requests to an empty action so far, but still amazing. </p>
<p>Well, since I can’t see the code, I remain skeptical and added the hidden id anyway. Witchcraft like this feels wrong, I like mysteries though.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/10/21/its-a-kind-of-magic-monorail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ActiveRecord&#8217;s Field mapping to map custom enumeration classes</title>
		<link>http://www.tigraine.at/2009/09/03/using-activerecords-field-mapping-to-map-custom-enumeration-classes/</link>
		<comments>http://www.tigraine.at/2009/09/03/using-activerecords-field-mapping-to-map-custom-enumeration-classes/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 11:28:10 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/09/03/using-activerecords-field-mapping-to-map-custom-enumeration-classes/</guid>
		<description><![CDATA[One thing that may be overlooked sometimes (I certainly did) is the ability of ActiveRecord to not only bind to properties but also to instance fields (yes, even private ones). This little feature came in very handy when I was looking for a way to persist a class based enumeration. I’ll tell you why in [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that may be overlooked sometimes (I certainly did) is the ability of ActiveRecord to not only bind to properties but also to instance fields (yes, even private ones). This little feature came in very handy when I was looking for a way to persist a <a href="http://www.tigraine.at/2009/08/02/a-better-way-to-write-enumerations/" target="_blank">class based enumeration</a>. I’ll tell you why in a minute. </p>
<p>First, I have Users that can be in one of 5 categories. None of which were important enough to warrant a foreign-key relationship modeling in the database, but I still wanted to encapsulate them in some sort of object to avoid doing string checking inside my code. The model looks like this:</p>
<p><a href="http://www.tigraine.at/wp-content/uploads/2009/09/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.tigraine.at/wp-content/uploads/2009/09/image_thumb.png" width="448" height="287" /></a> </p>
<p>I clearly didn’t want to have a Category table in my database, so I decided on creating the Category class while saving the Name property to the database. </p>
<p>Here is my implementation of the <tt>User.Category</tt> field:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:aed6ec28-1ca0-45eb-9b18-bd0ea7676c70" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
[Field]
private string category;

public Category Category
{
&#160;&#160;&#160;&#160;get { return Category.GetCategoryByName(category); }
&#160;&#160;&#160;&#160;set { category = value.Name; }
}
</pre>
</div>
<p>As you can clearly see. My code is only dealing with Category objects (that can have implementations attached) while behind the scenes I only write the name of the category to the backing field. This way I get rid of magic strings inside my code while not having to burden my database with foreign key constraints.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/09/03/using-activerecords-field-mapping-to-map-custom-enumeration-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How MonoRail selects it&#8217;s best ActionMethod candidate: CalculateParamPoints</title>
		<link>http://www.tigraine.at/2009/08/27/how-monorail-selects-its-best-actionmethod-candidate-calculateparampoints/</link>
		<comments>http://www.tigraine.at/2009/08/27/how-monorail-selects-its-best-actionmethod-candidate-calculateparampoints/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 13:47:07 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/08/27/how-monorail-selects-its-best-actionmethod-candidate-calculateparampoints/</guid>
		<description><![CDATA[James Curran pointed me at one interesting flaw with my implementation of the DefaultValueAttribute for MonoRail I blogged about some weeks ago. This tipped me off to actually read the MonoRail code to find out how exactly MonoRail selects what overload of a ActionMethod to call.
MonoRail’s approach is as simple as it is brilliant, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://honestillusion.com/Default.aspx" target="_blank">James Curran</a> <a href="http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/#comment-3250" target="_blank">pointed me at</a> one interesting flaw with my implementation of the <a href="http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/" target="_blank">DefaultValueAttribute for MonoRail</a> I blogged about some weeks ago. This tipped me off to actually read the MonoRail code to find out how exactly MonoRail selects what overload of a ActionMethod to call.</p>
<p>MonoRail’s approach is as simple as it is brilliant, and reading the code that does this is a very pleasant experience. It took about 5 minutes to figure out the following:</p>
<p><font style="background-color: #ffffff">If there are multiple public methods in a <tt>SmartDispatcherController </tt>that match the request’s action, MonoRail calculates a score of parameter points of each overload, picking the “heaviest” and executes it.       <br /></font>How that score is calculated is quite simple: Every matched parameter gets 10 points, unmatched 0.</p>
<p><font style="background-color: #ffffff">But there’s more detail to this:</font></p>
<p><font style="background-color: #ffffff">Every regular parameter (types not defining a attribute of IParameterBinder) where the parameter-name could be matched to the request parameter’s key, MR assumes assumes a weight of 10</font></p>
<p><font style="background-color: #ffffff">In detail this means: Given the following ActionMethod with two parameters:      <br /></font></p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:ba5280de-2599-41f5-a0fe-834f37099c81" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public void Test(string category, int page)
{&#160;&#160;&#160;&#160;
}
</pre>
</div>
<p>Monorail will assign 10 points if the key “category” could be found in the server’s request object (<tt>Request[&quot;category&quot;]</tt>) and another 10 if a parameter key called “page” is also present. </p>
<p>So the following call <a href="http://localhost/Home/Test.rails?category=beer&amp;page=1">/Test.rails?category=beer&amp;page=1</a> would account for 20 parameter points, whereas omitting <tt>page</tt> would result in only 10 points. MonoRail will then pick the method with the highest score of matched parameter points and call it with those parameters.</p>
<p>Now, obviously the following would lead to a disambiguation:</p>
<p><a href="http://localhost/">/Test.rails?category=beer</a></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:3157342b-b5df-4aad-86d4-b9ac5cc078cd" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public void Test(string category, int page)
{&#160;&#160;&#160;&#160;
}
public void Test(string category)
{
}
</pre>
</div>
<p>Category is present in both cases and page is unmatched, so both methods get 10 points and no useful distinction can be made. This is where MonoRail will award <u>a bonus of 5 points </u>to a method where all parameters could be matched. Thus giving <tt>Test(string)</tt> 15 points and <tt>Test(string, int)</tt> only 10, leading to the right match.</p>
<p>Now, in case of a parameter that is decorated with a <tt>IParameterBinder</tt> attribute (like ARFetch, DataBind etc) calculating those parameter points is delegated to the attribute class that then returns a score following it’s own logic (e.g.: if one attribute collects data from multiple request parameters it could return more than 10)</p>
<p>Let’s look at a sample implementation of <tt>CalculateParamPoints</tt> of the <tt>ARFetchAttribute</tt>:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:2532bfc5-a66c-437d-9e0a-01b6030c3bd0" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public virtual int CalculateParamPoints(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
{
	String paramName = RequestParameterName ?? parameterInfo.Name;

	return context.Request.Params.Get(paramName) != null ? 10 : 0;
}
</pre>
</div>
<p>As you can see, ARFetch follows the usual MonoRail behavior and will return 10 in case it’s parameter-name could be matched, or 0 otherwise. </p>
<p>Still, all this doesn’t negate the fact that you could end up with ambiguities between action methods. In case many methods received the same number of parameter points MonoRail will simply call the first.</p>
<p>Oh, and did I mention that ASP.NET MVC can overload only on a per-http-verb basis? (Given that that’s a quite finite number <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs.aspx" target="_blank">of exactly 5</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/08/27/how-monorail-selects-its-best-actionmethod-candidate-calculateparampoints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing binary data in NHibernate / ActiveRecord</title>
		<link>http://www.tigraine.at/2009/08/19/storing-binary-data-in-nhibernate-activerecord/</link>
		<comments>http://www.tigraine.at/2009/08/19/storing-binary-data-in-nhibernate-activerecord/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:47:11 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/08/19/storing-binary-data-in-nhibernate-activerecord/</guid>
		<description><![CDATA[I believe the simplest way to store binary data is to just put in the database. Whenever I’ve agreed to throw data to a disk I’ve had issues with deployment, administration or disaster recovery. 
Simply put: Once you have a dependency from your database to your file system, you no longer have the luxury of [...]]]></description>
			<content:encoded><![CDATA[<p>I believe the simplest way to store binary data is to just put in the database. Whenever I’ve agreed to throw data to a disk I’ve had issues with deployment, administration or disaster recovery. </p>
<p>Simply put: Once you have a dependency from your database to your file system, you no longer have the luxury of only thinking about recovering the database. You now need to keep two pieces of your system “safe”, both requiring a completely different toolset than the other. </p>
<p>Besides the obvious second point of headache for backup/recovery, you also bring yourself into a world of hurt for deployment / maintenance scenarios.    <br />Filesystem access rights can be a huge pain in the ass, and having to set them right (and keep them that way) is usually a time-bomb waiting to go off. </p>
<p>So, storing your binary data in the db solves many problems, but some new ones arise. Mostly implementation details, but I’d like to show you some things to keep in mind when writing binary data to db. </p>
<p><strong>NHibernate supports no lazy loading of instance fields</strong></p>
<p><a href="http://www.tigraine.at/wp-content/uploads/2009/08/image5.png"><img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.tigraine.at/wp-content/uploads/2009/08/image-thumb4.png" width="221" height="132" /></a> While with conventional ADO.NET I’d just put the binary data as a column inside the table it belongs to, NHibernate requires you to do things different. If you map your data like that NHibernate will fetch it whenever you read objects from that table, meaning that you’ll be querying large binary data fields for no reason, causing you application performance to significantly degrade over time. </p>
<p>&#160;</p>
<p>What you want is to have NHibernate fetch that field only if it is accessed (lazy load it), and that’s not possible for fields inside a class, but it is possible for references. So your database schema should look like this:</p>
<p><a href="http://www.tigraine.at/wp-content/uploads/2009/08/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.tigraine.at/wp-content/uploads/2009/08/image-thumb5.png" width="676" height="171" /></a> </p>
</p>
<p>And your mapping will look similar to this (I’ll use ActiveRecord for easier understanding):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:9799a8e6-f500-4709-b2b1-715dace4fa21" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
[ActiveRecord]
public class Invoice : ActiveRecordBase&lt;Invoice&gt;
{
&#160;&#160;&#160;&#160;[PrimaryKey]
&#160;&#160;&#160;&#160;public int Id { get; set; }

&#160;&#160;&#160;&#160;[BelongsTo(Lazy = FetchWhen.OnInvoke, Cascade = CascadeEnum.SaveUpdate)]
&#160;&#160;&#160;&#160;public BinaryData ScannedInvoice { get; set; }
}

[ActiveRecord]
public class BinaryData : ActiveRecordBase&lt;BinaryData&gt;
{
&#160;&#160;&#160;&#160;[PrimaryKey]
&#160;&#160;&#160;&#160;public int Id { get; set; }

&#160;&#160;&#160;&#160;[Property(ColumnType = "BinaryBlob", SqlType = "IMAGE", NotNull = true)]
&#160;&#160;&#160;&#160;public byte[] Data { get; set; }
}
</pre>
</div>
<p>Now whenever your Invoice is saved/inserted NHibernate will also check if <tt>BinaryData </tt>has to be updated/inserted, while only loading the binary field if you actually access the <tt>Invoices.ScannedInvoice </tt>field. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/08/19/storing-binary-data-in-nhibernate-activerecord/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>DefaultValue attribute for Castle MonoRail</title>
		<link>http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/</link>
		<comments>http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 10:09:25 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/</guid>
		<description><![CDATA[While reading through ScottGu’s announcement of the ASP.NET MVC 2 Preview 1 I noticed this rather interesting little feature that’s in there:
 
MonoRail is much smarter about action methods than MVC so there are already things going on with default values through routing etc. But this particular thing wasn’t in the framework until now. So [...]]]></description>
			<content:encoded><![CDATA[<p>While reading through <a href="http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx">ScottGu’s announcement of the ASP.NET MVC 2 Preview 1</a> I noticed this rather interesting little feature that’s in there:</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DefaultValue attribute in ActionMethod" border="0" alt="DefaultValue attribute in ActionMethod" src="http://www.tigraine.at/wp-content/uploads/2009/08/step19.png" width="621" height="78" /></a> </p>
<p>MonoRail is <a href="http://www.tigraine.at/2009/07/31/mvc-vs-monorail-action-methods/" target="_blank">much smarter about action methods</a> than MVC so there are already things going on with default values through routing etc. But this particular thing wasn’t in the framework until now. So I took <a href="http://www.kenegozi.com/blog/2008/09/15/creating-a-custom-parameter-binder-for-monorail-actions-iparameterbinder.aspx" target="_blank">Ken Egozi’s sample</a> about using <tt>IParameterBinder </tt>to implement the <tt>DefaultValueAttribute </tt>in MonoRail.</p>
<p>The result in syntax is identical to ASP.NET MVC 2 P1 and it was very easy to do:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:6720626e-6c92-4f24-8966-4562a682642c" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public void Browse([DefaultValue("beer")] string category, [DefaultValue(1)] int page)
{
&#160;&#160;&#160;&#160;
}
</pre>
</div>
<p>How is this done? Well, I suggest you read <a href="http://www.kenegozi.com/blog/2008/09/15/creating-a-custom-parameter-binder-for-monorail-actions-iparameterbinder.aspx" target="_blank">Ken Egozi’s post</a> since he does a much better job at explaining that thing. Anyway, here is the code to make that happen:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:377739e2-84f1-4f8d-a880-717ccccb7ef7" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
using System;
using System.Reflection;
using Castle.MonoRail.Framework;

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public class DefaultValueAttribute : Attribute, IParameterBinder
{
	private readonly object value;
	public DefaultValueAttribute(object value)
	{
		this.value = value;
	}

	public int CalculateParamPoints(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
	{
		var token = context.Request[parameterInfo.Name];
		if (CanConvert(parameterInfo.ParameterType, token))
			return 10;
		return 0;
	}

	private static bool CanConvert(Type targetType, string token)
	{
		if (token == null)
			return false;

		try
		{
			Convert.ChangeType(token, targetType);
			return true;
		}
		catch (FormatException)
		{
			return false;
		}
	}

	public object Bind(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
	{
		string token = context.Request[parameterInfo.Name];
		Type type = parameterInfo.ParameterType;
		if (CanConvert(type, token))
			return Convert.ChangeType(token, type);
		return value;
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/08/04/defaultvalue-attribute-for-castle-monorail/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MVC vs MonoRail &#8211; Action Methods</title>
		<link>http://www.tigraine.at/2009/07/31/mvc-vs-monorail-action-methods/</link>
		<comments>http://www.tigraine.at/2009/07/31/mvc-vs-monorail-action-methods/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:02:50 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/07/31/mvc-vs-monorail-action-methods/</guid>
		<description><![CDATA[Many people have said nasty things about the Castle MonoRail framework since ASP.NET MVC has come out. Both serve the same purpose but both frameworks are pretty different. I did/do projects in both these days, and usually all features of A are also present in B, just slightly different. 
One thing where this isn’t true [...]]]></description>
			<content:encoded><![CDATA[<p>Many people have said nasty things about the Castle MonoRail framework since ASP.NET MVC has come out. Both serve the same purpose but both frameworks are pretty different. I did/do projects in both these days, and usually all features of A are also present in B, just slightly different. </p>
<p>One thing where this isn’t true is the layout of ActionMethods in MVC:</p>
<p>In short, MonoRail can have unlimited method overloads for ActionMethods while MVC can only overload twice (once for each HttpVerb). </p>
<p>What do I mean?</p>
<p>MVC:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:c76a91dc-46e8-4fde-bd10-3d0879fe7f46" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public class HomeController : Controller
{
&#160;&#160;&#160;&#160;public ActionResult Index()
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return View();
&#160;&#160;&#160;&#160;}

&#160;&#160;&#160;&#160;[AcceptVerbs(HttpVerbs.Post)]
&#160;&#160;&#160;&#160;public ActionResult Index(int id)
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return View();
&#160;&#160;&#160;&#160;}
}
</pre>
</div>
<p>MonoRail:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:3392e32c-3548-4c97-bfb0-e1d9902dc228" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
public class ContactController : SmartDispatcherController
{
&#160;&#160;&#160;&#160;public void Index()
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;}

&#160;&#160;&#160;&#160;public void Index(int id)
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;}

&#160;&#160;&#160;&#160;public void Index(int id, string name)
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;}
}
</pre>
</div>
<p>You can see clearly, MonoRail as a framework is much smarter about what action method it will invoke. Based on what parameters you supply it will pick the best match.&#160; <br />MVC will simply use reflection to invoke any method with that name that matches the <tt>HttpVerb</tt>, so once you remove the <tt>AcceptVerbs </tt>attribute MVC will break with a <tt>AmbiguousMatchException</tt>.</p>
<h4>MVC vs MonoRail</h4>
<p>Just to get bias out of the way: I believe MVC is technically still inferior to MonoRail but makes that up in larger community and (much) better documentation. What you pick is largely dependant on how well you know your way around missing documentation and open source code mailing lists. </p>
<p>To illustrate this I went to <a href="http://stackoverflow.com/">stackoverflow</a> and compared the number of questions tagged with <a href="http://stackoverflow.com/questions/tagged/asp.net-mvc">asp.net-mvc</a> with those tagged <a href="http://stackoverflow.com/questions/tagged/castle-monorail">castle-monorail</a>. The results may very well speak for themselves:</p>
<p><a href="http://www.tigraine.at/wp-content/uploads/2009/07/image15.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.tigraine.at/wp-content/uploads/2009/07/image-thumb11.png" width="444" height="130" /></a> </p>
<p>It’s a shame I have to say. MonoRail is such a nice framework and it really does not deserve getting stomped by ASP.NET MVC. As funny as this may sound for a OSS project, currently the best way to contribute to MonoRail is <a href="http://www.tigraine.at/category/programmierung/net/castle/">to write about it</a> and if possible <a href="http://www.tigraine.at/2009/05/26/rails-with-obstacles/">improve documentation around it</a>. I guess that says everything about the quality/maturity of the framework. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/07/31/mvc-vs-monorail-action-methods/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Keeping up with Castle binaries through NAnt</title>
		<link>http://www.tigraine.at/2009/07/25/keeping-up-with-castle-binaries-through-nant/</link>
		<comments>http://www.tigraine.at/2009/07/25/keeping-up-with-castle-binaries-through-nant/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 13:55:25 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/07/25/keeping-up-with-castle-binaries-through-nant/</guid>
		<description><![CDATA[One of the main annoyances of running from the castle trunk for me was copying new assemblies to my projects. Whenever I see something interesting pop up in the mailing list I usually run a SVN update to see what changed. While the castle build process is pretty simple at this point, picking the right [...]]]></description>
			<content:encoded><![CDATA[<p>One of the main annoyances of running from the castle trunk for me was copying new assemblies to my projects. Whenever I see something interesting pop up in the mailing list I usually run a SVN update to see what changed. While the castle build process is pretty simple at this point, picking the right assemblies and copying them to an ongoing project manually is just painful. </p>
<p>I did this exactly twice before I remembered the golden rule: <strong><u>automate</u></strong>!</p>
<p>This little NAnt target is now in charge of copying assemblies I need to my <a href="http://www.tigraine.at/2008/10/13/handling-dependencies/">project’s lib directory</a>:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:51228e84-0f73-4551-b35c-725a6f6ae28a" class="wlWriterEditableSmartContent">
<pre name="code" class="xml">
&lt;target name="castle-update"&gt;
&lt;if test="${property::exists('castle-trunk-dir')}"&gt;

	&lt;if test="${property::exists('skip-castle-compile') == false}"&gt;
		&lt;echo message="Compiling castle trunk release binaries..." /&gt;
		&lt;exec program="build.cmd" basedir="${castle-trunk-dir}" workingdir="${castle-trunk-dir}"&gt;
		&lt;/exec&gt;
	&lt;/if&gt;

	&lt;echo message="copying castle binaries" /&gt;

	&lt;copy todir="lib\castle"&gt;
		&lt;fileset basedir="${castle-trunk-dir}\build\net-3.5\release\"&gt;
			&lt;include name="Castle.ActiveRecord.???" /&gt;
			&lt;include name="Castle.Components.Binder.???" /&gt;
			&lt;include name="Castle.Components.Common.EmailSender.???" /&gt;
			&lt;include name="Castle.Components.Common.TemplateEngine.???" /&gt;
			&lt;include name="Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.???" /&gt;
			&lt;include name="Castle.Components.DictionaryAdapter.???" /&gt;
			&lt;include name="Castle.Components.Pagination.???" /&gt;
			&lt;include name="Castle.Components.Validator.???" /&gt;
			&lt;include name="Castle.Core.???" /&gt;
			&lt;include name="Castle.DynamicProxy2.???" /&gt;
			&lt;include name="Castle.MonoRail.ActiveRecordSupport.???" /&gt;
			&lt;include name="Castle.MonoRail.Framework.???" /&gt;
			&lt;include name="Castle.MonoRail.Framework.Views.NVelocity.???" /&gt;
			&lt;include name="Castle.MonoRail.TestSupport.???" /&gt;
			&lt;include name="Castle.Services.Logging.Log4netIntegration.???" /&gt;
			&lt;include name="Iesi.Collections.???" /&gt;
			&lt;include name="log4net.???" /&gt;
			&lt;include name="*.license.txt" /&gt;
			&lt;include name="NHibernate.ByteCode.Castle.???" /&gt;
			&lt;include name="NHibernate.???" /&gt;
			&lt;include name="NVelocity.???" /&gt;
		&lt;/fileset&gt;
	&lt;/copy&gt;
&lt;/if&gt;
&lt;if test="${property::exists('castle-trunk-dir') == false}"&gt;
	&lt;fail message="Please specify the directory to castle-trunk through -D:castle-trunk-dir=&lt;directory&gt;" /&gt;
&lt;/if&gt;
&lt;/target&gt;
</pre>
</div>
<p>This little script will compile castle and then copy over all files I need to my <tt>/lib/castle</tt> folder, making a castle update as easy as writing:</p>
<blockquote><p><tt></p>
<p>build castle-update -D:castle-trunk-dir=..\open-source\castle-trunk</p>
<p>  </tt></p></blockquote>
<p>Make sure you have your <tt>/lib/</tt> folder under source control in case some breaking changes come from the new castle binaries. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/07/25/keeping-up-with-castle-binaries-through-nant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping up with Castle</title>
		<link>http://www.tigraine.at/2009/07/25/keeping-up-with-castle/</link>
		<comments>http://www.tigraine.at/2009/07/25/keeping-up-with-castle/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 12:45:47 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2009/07/25/keeping-up-with-castle/</guid>
		<description><![CDATA[Especially when trying to follow the development of a big project like Castle you can get lost quickly. There is no real “main” endpoint to refer to. Some news get out there through the development mailing list, sometimes they come through blogs and sometimes they are only present in code.
What I found useful in following [...]]]></description>
			<content:encoded><![CDATA[<p>Especially when trying to follow the development of a big project like Castle you can get lost quickly. There is no real “main” endpoint to refer to. Some news get out there through the development mailing list, sometimes they come through blogs and sometimes they are only present in code.</p>
<p>What I found useful in following the project are the following places:</p>
<ol>
<li><a href="http://pipes.yahoo.com/pipes/pipe.run?_id=bGjr2c1s3hGi5qx20EypaA&amp;_render=rss&amp;limit=200">Castle Project aggregator</a> – a aggregate feed of most known figures involved in the castle development process</li>
<li><a href="http://groups.google.com/group/castle-project-devel?hl=en">Castle Project development mailing list</a> – The place where discussion about features and structure happens</li>
<li><a href="http://www.castleproject.org:8090/viewType.html?buildTypeId=bt2&amp;tab=buildTypeChangeLog">Castle Project svn log</a> – I like to look at commits to see what’s going on</li>
</ol>
<ol>Note: Especially with castle where the last “official” release was in 2007 it’s imo quite important to know what’s going on when you are running the trunk version.</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2009/07/25/keeping-up-with-castle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
