<?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>Zen and the art of Castle maintenance</title>
	<atom:link href="http://hammett.castleproject.org/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://hammett.castleproject.org</link>
	<description>Open source and life (or should it read Open source or life?)</description>
	<lastBuildDate>Fri, 13 Jan 2012 22:42:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Help Emilie</title>
		<link>http://hammett.castleproject.org/index.php/2012/01/help-emilie/</link>
		<comments>http://hammett.castleproject.org/index.php/2012/01/help-emilie/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 22:42:21 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=391</guid>
		<description><![CDATA[If you heard the story on radiolab, you know her. If you havent, then do it.]]></description>
			<content:encoded><![CDATA[<p>If you heard the story on <a href="http://www.radiolab.org/">radiolab</a>, you know her. If you havent, then <a href="http://www.radiolab.org/2011/jan/25/finding-emilie/">do it</a>. </p>
<p><embed src="http://widget.chipin.com/widget/id/41fb344ae81af41a" flashVars="color_scheme=gray" type="application/x-shockwave-flash" allowScriptAccess="always" wmode="transparent" width="250" height="250"></embed></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2012/01/help-emilie/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2012/01/help-emilie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MEF scopes to support service overrides</title>
		<link>http://hammett.castleproject.org/index.php/2011/12/using-mef-scopes-to-support-service-overrides/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/12/using-mef-scopes-to-support-service-overrides/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 21:02:55 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MEF]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=387</guid>
		<description><![CDATA[One of the coolest thing in the newest version of MEF is scoping support. Not because I&#8217;ve participated in designing and eventually patented some aspects of it &#8211; not at all &#8211; but because it&#8217;s actually quite helpful. Scopes, as you can imagine, allow you to define isolated &#8220;bubbles&#8221; of composition. On the components side, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the coolest thing in the newest version of MEF is scoping support. Not because I&#8217;ve participated in designing and eventually patented some aspects of it &#8211; not at all &#8211; but because it&#8217;s actually quite helpful. </p>
<p>Scopes, as you can imagine, allow you to define isolated &#8220;bubbles&#8221; of composition. </p>
<p>On the components side, we use an ExportFactory<T> (should have been ScopeFactory<T>, but dont get me started on this one) with CreationPolicy.NewScope (ughh) to achieve this behavior. On the hosting side, you need to define an hierarchy of CompositionScopeDefinition and give it to the container. </p>
<p>One thing that is particularly handy in IoC containers is supporting default services, but allow for overrides. Windsor even use this taxonomy. The following is a trick that uses scopes to achieve the same behavior. </p>
<p>Before saying that it&#8217;s easier, simpler, faster to achieve that using Container X, Y or Z, remember that MEF is all about federated systems, and that comes with challenges and constraints. </p>
<p>Here&#8217;s the trick: I define three scopes: Default, Overrides and App. All default services are bound to the Default scope. The app level components live in the App scope. In the middle, the Override scopes will be used to replace default services. </p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="cs"><div class="devcodeoverflow"></pre>
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;

    class Program
    {
        static void Main(string[] args)
        {
            var ubber = new AssemblyCatalog(typeof (Program).Assembly);

            var defLevelCat = ubber.Filter(cpd =&gt; cpd.ContainsPartMetadata(&quot;Scope&quot;, &quot;Default&quot;));
            var overLevelCat = defLevelCat.Complement.Filter(cpd =&gt; cpd.ContainsPartMetadata(&quot;Scope&quot;, &quot;Override&quot;));
            var appLevelCat = overLevelCat.Complement.Filter(cpd =&gt; cpd.ContainsPartMetadata(&quot;Scope&quot;, &quot;App&quot;));

            var appDef = new CompositionScopeDefinition(appLevelCat, new CompositionScopeDefinition[0],
                                                        appLevelCat.Parts.SelectMany(p =&gt; p.ExportDefinitions));
            var overDef = new CompositionScopeDefinition(overLevelCat, new [] { appDef },
                                                         overLevelCat.Parts.SelectMany(p =&gt; p.ExportDefinitions));
            var defDef = new CompositionScopeDefinition(defLevelCat, new[] { overDef },
                                                        defLevelCat.Parts.SelectMany(p =&gt; p.ExportDefinitions));

            var cont = new CompositionContainer(defDef);

            var entryPoint = cont.GetExportedValue&lt;EntryPoint&gt;();
            var sndLevel = entryPoint.Creator.CreateExport().Value;
            var lastLevel = sndLevel.Creator.CreateExport().Value;
            var component = lastLevel.com;

        }
    }

    [Export]
    [PartMetadata(&quot;Scope&quot;, &quot;Default&quot;)]
    public class EntryPoint
    {
        [Import(RequiredCreationPolicy = CreationPolicy.NewScope, AllowDefault = true)]
        public ExportFactory&lt;OverrideLevelScopeCreator&gt; Creator { get; set; }
    }

    [Export]
    [PartMetadata(&quot;Scope&quot;, &quot;Override&quot;)]
    public class OverrideLevelScopeCreator
    {
        [Import(RequiredCreationPolicy = CreationPolicy.NewScope, AllowDefault = true)]
        public ExportFactory&lt;AppLevelScopeCreator&gt; Creator { get; set; }        
    }

    [Export]
    [PartMetadata(&quot;Scope&quot;, &quot;App&quot;)]
    public class AppLevelScopeCreator
    {
        [Import]
        public Component com { get; set; }
    }

    public interface IService
    {
    }

    [Export(typeof(IService))]
    [PartMetadata(&quot;Scope&quot;, &quot;Default&quot;)]
    public class DefaultService : IService
    {
    }

    [Export(typeof(IService))]
    [PartMetadata(&quot;Scope&quot;, &quot;Override&quot;)]
    public class OverrideService : IService
    {
        [Import(Source = ImportSource.NonLocal)]
        public IService ServParent { get; set; }
    }
    
    [Export, PartMetadata(&quot;Scope&quot;, &quot;App&quot;)]
    public class Component
    {
        [Import]
        public IService Serv { get; set; }
    }
</pre></div></pre><!--END_DEVFMTCODE--></p>
<p>Have fun!</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/12/using-mef-scopes-to-support-service-overrides/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/12/using-mef-scopes-to-support-service-overrides/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A &#8220;decent&#8221; DirectoryCatalog implementation</title>
		<link>http://hammett.castleproject.org/index.php/2011/12/a-decent-directorycatalog-implementation/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/12/a-decent-directorycatalog-implementation/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 21:02:06 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[MEF]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=378</guid>
		<description><![CDATA[Yes, I&#8217;ve raised this with the MEF team many times. It&#8217;s easier to go and do it yourself. The issue is that DirectoryCatalog does not guard against failures on loading types (which is quite common as soon as you start working on real projects as opposed to samples &#8211; hint hint!). So here&#8217;s a better [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, I&#8217;ve raised this with the MEF team many times. It&#8217;s easier to go and do it yourself. </p>
<p>The issue is that DirectoryCatalog does not guard against failures on loading types (which is quite common as soon as you start working on real projects as opposed to samples &#8211; hint hint!). So here&#8217;s a better version (in F#):</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="cs"><div class="devcodeoverflow"><pre>
    type DirectoryCatalogGuarded(folder) = 
        inherit ComposablePartCatalog()

        let _catalogs = List<TypeCatalog>()
        let mutable _parts : ComposablePartDefinition seq = null

        let load_assembly_guarded (file:string) = 
            try
                let name = AssemblyName.GetAssemblyName(file);
                Assembly.Load name
            with | ex -> null

        let guard_load_types (asm:Assembly) =
          try
              asm.GetTypes()
          with | :? ReflectionTypeLoadException as exn -> exn.Types

        do 
            let files = Directory.GetFiles(folder, "*.dll")
            for file in files do
                let asm = load_assembly_guarded file
                if asm <> null then
                    let types = guard_load_types(asm) |> Seq.filter (fun t -> t <> null) 
                    if not (Seq.isEmpty types) then
                        _catalogs.Add (new TypeCatalog(types))
            _parts <- _catalogs |> Seq.collect (fun c -> c.Parts) 

        override x.Parts = _parts.AsQueryable()

        override x.GetExports(definition) = 
            _catalogs |> Seq.collect (fun c -> c.GetExports(definition))
</pre></div></pre><!--END_DEVFMTCODE--></p>
<p>The &#8220;trick&#8221; is to catch <a href="http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.aspx">ReflectionTypeLoadException</a> &#8211; something I learned from <a href="http://davesbox.com/">David</a>. This exception gives you a list of types it was able to load. Mind you, nulls may exists in the list hence the filtering. </p>
<p>The shortcoming here is that by bypassing the AssemblyCatalog, you wont be able to use CatalogReflectionContextAttribute &#8211; which I believe I&#8217;m one of the ten people on earth that knows what it&#8217;s for, so no biggy I guess?</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/12/a-decent-directorycatalog-implementation/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/12/a-decent-directorycatalog-implementation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FAKE impressions</title>
		<link>http://hammett.castleproject.org/index.php/2011/08/fake-impressions/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/08/fake-impressions/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 09:22:02 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=374</guid>
		<description><![CDATA[Weird post title, I know. But I refer to FAKE &#8211; F# Make. It&#8217;s a nice and simple library to perform usual build related tasks. The fact that it&#8217;s pure F# makes it quite powerful &#8211; have you tried doing complex stuff with NAnt or MSBuild? If so, you know what I mean. Xml is [...]]]></description>
			<content:encoded><![CDATA[<p>Weird post title, I know. But I refer to <a href="https://github.com/forki/FAKE">FAKE</a> &#8211; F# Make. </p>
<p>It&#8217;s a nice and simple library to perform usual build related tasks. The fact that it&#8217;s pure F# makes it quite powerful &#8211; have you tried doing complex stuff with NAnt or MSBuild? If so, you know what I mean. Xml is *not* a programming language. </p>
<p>FAKE is simply organized as a collection of modules, each exposing related functions and|or operator overloads. So it&#8217;s not exposed in an OOP fashion, rather in a very flat public surface. That *may* make up for the lack of documentation. It&#8217;s somewhat easy to understand how things work by browsing the source &#8211; for those who are comfortable with that. </p>
<p>That said, in my first experience I couldn&#8217;t get the FileSet to generate any result. I also couldn&#8217;t find a way to turn on a more verbose logging. I went on a trial-and-error and realized the fileset was missing a BaseDir setting. </p>
<p>Since I&#8217;m a big fan of <a href="http://fsprojectextender.codeplex.com/">F# Project Extender</a>, which adds metadata to define the order of the build items that are not recognized by MSBuild. So I managed to create a FscTask that takes that in consideration. In the process I noticed how FAKE lacks a few common NAnt features, such as resolving reference assemblies. I guess the author didn&#8217;t need them, which is fair in the OSS world. That said, a simple Fsc.exe invocation turned into a sizable task.</p>
<p>My fsc task is dirty and ugly, so beware. You can <a href="https://github.com/castleproject/Castle.MonoRail3/blob/master/buildscripts/BuildProj/BuildProj/Program.fs">find it here</a>. For now I&#8217;m sticking to Fake for MR builds and see how it goes. </p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/08/fake-impressions/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/08/fake-impressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MR 3 update / Castle Blade</title>
		<link>http://hammett.castleproject.org/index.php/2011/07/mr-3-update-castle-blade/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/07/mr-3-update-castle-blade/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 00:28:01 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[MonoRail]]></category>
		<category><![CDATA[OSS]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=365</guid>
		<description><![CDATA[Fun times! Since I&#8217;ve left MS I&#8217;ve been working on a real web site/backend/frontend &#8211; you know, doing actual work instead of long meaningless meetings, doc writing and one-on-ones with managers setting you up for failure (I wonder if I should make one of my &#8216;reviews&#8217; public, so you&#8217;ll see the amount of BS I [...]]]></description>
			<content:encoded><![CDATA[<p>Fun times! Since I&#8217;ve left MS I&#8217;ve been working on a real web site/backend/frontend &#8211; you know, doing actual work instead of long meaningless meetings, doc writing and one-on-ones with managers setting you up for failure (I wonder if I should make one of my &#8216;reviews&#8217; public, so you&#8217;ll see the amount of BS I had to put up with). </p>
<h3>WebSockets</h3>
<p>Anyway, the first work was to create a websockets server. That was fun especially since F# offers its async workflow support and <a href="http://msdn.microsoft.com/en-us/library/ee370357%28VS.100%29.aspx">MailboxProcessor</a>. It&#8217;s fun to think about it. While at MS, <a href="http://blogs.msdn.com/b/mirceat/">one</a> of my friends there wouldn&#8217;t stop bitching about how F# is incredibly superior to C#. Gosh, he was right.. </p>
<p>The company I&#8217;m doing the work for and I are discussing whether we will make the websocket server available commercially. It&#8217;s a PITA to implement the protocols, to test them and keep up, since the spec is in progress. So, sorry, won&#8217;t be doing all this work for free. </p>
<h3>Ideas playground</h3>
<p>On the MonoRail end, we&#8217;ve been using it extensively and coding up functionality as needed &#8211; by we I mean Henry and I. It&#8217;s been quite a journey to reassess all the design decisions in MR1/2, and also evaluate what&#8217;s out there. I&#8217;m sure we learn more from our mistakes than anything else. <a href="http://bugsquash.blogspot.com/">Mauricio</a> is pushing some interesting ideas on web frameworks that are making me reevaluate our proposed API over and over again. Now that I&#8217;m quite familiar with <a href="http://www.quanttec.com/fparsec/">FParsec</a>, the idea of using combinators to compose forms (formlets) is enticing. It&#8217;s just strike me as something hard to expose in C#, we would need a different API and I&#8217;m sure it would be awfully verbose. </p>
<h3>Castle.Blade = ++Razor</h3>
<p>I love Razor&#8217;s simplicity and tooling support. Achieving simplicity is a major accomplishment, and the guys at the ASP.NET team did it. I remember when Scott Hunter gave us a preview of what at the time was code named Plan9. Awesome work!</p>
<p>I&#8217;ve then decided to make Razor the main view engine for MR3. However, when I started to experiment with a better API for our helpers library I bumped into some not-so-nice limitations from Razor. For example, I wanted to be able to express something like:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Rails"><div class="devcodeoverflow">
<span style="color:#0066ff; font-weight:bold;">@Form</span>.<span style="color:#9900CC;">For</span><span style="color:#006600; font-weight:bold;">&#40;</span>..., <span style="color:#006600; font-weight:bold;">&#123;</span>
	<span style="color:#006600; font-weight:bold;">//</span> this is a block
        <span style="color:#0066ff; font-weight:bold;">@builder</span>.<span style="color:#9900CC;">EditorFor</span><span style="color:#006600; font-weight:bold;">&#40;</span>m <span style="color:#006600; font-weight:bold;">=&gt;</span> m.<span style="color:#9900CC;">Name</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>Well, Razor does support translating a mix of content and code block into a delegate &#8211; which is neat. The limitation is that they cannot be nested, and the parameter name is restricted to &#8220;item&#8221;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Rails"><div class="devcodeoverflow">
<span style="color:#0066ff; font-weight:bold;">@Form</span>.<span style="color:#9900CC;">For</span><span style="color:#006600; font-weight:bold;">&#40;</span>..., @<span style="color:#006600; font-weight:bold;">&#123;</span>
        <span style="color:#0066ff; font-weight:bold;">@item</span>.<span style="color:#9900CC;">EditorFor</span><span style="color:#006600; font-weight:bold;">&#40;</span>m <span style="color:#006600; font-weight:bold;">=&gt;</span> m.<span style="color:#9900CC;">Name</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>The issue is that &#8220;item&#8221; is not very expression. I&#8217;ve spent many hours digging into Razor&#8217;s code trying for find a way to work-around this limitation (by using its extension points, not changing their code). At some point it was clear that coding up my own parser and translator would be easier. Castle Blade then came to fruition. </p>
<p>Blade intends to be 100% backward compatible with Razor, and introduces a few (one?) different transition marks to overcome Razor&#8217;s limitations. For the example above, we would use:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Rails"><div class="devcodeoverflow">
<span style="color:#0066ff; font-weight:bold;">@Form</span>.<span style="color:#9900CC;">For</span><span style="color:#006600; font-weight:bold;">&#40;</span>..., @<span style="color:#006600; font-weight:bold;">=&gt;</span> builder <span style="color:#006600; font-weight:bold;">&#123;</span>
        <span style="color:#0066ff; font-weight:bold;">@builder</span>.<span style="color:#9900CC;">EditorFor</span><span style="color:#006600; font-weight:bold;">&#40;</span>m <span style="color:#006600; font-weight:bold;">=&gt;</span> m.<span style="color:#9900CC;">Name</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>The @=> transition signals that a delegate will be created for the block, and the parameter name is the one that follows. In theory more than a single parameter is supported. </p>
<p>We also support nested blocks, which allows for the something like the following:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Rails"><div class="devcodeoverflow">
<span style="color:#0066ff; font-weight:bold;">@Form</span>.<span style="color:#9900CC;">For</span><span style="color:#006600; font-weight:bold;">&#40;</span>..., @<span style="color:#006600; font-weight:bold;">=&gt;</span> builder <span style="color:#006600; font-weight:bold;">&#123;</span>
        builder.<span style="color:#9900CC;">FormTemplate</span><span style="color:#006600; font-weight:bold;">&#40;</span>@<span style="color:#006600; font-weight:bold;">=&gt;</span> t <span style="color:#006600; font-weight:bold;">&#123;</span>
                <span style="color:#006600; font-weight:bold;">&lt;</span>div<span style="color:#006600; font-weight:bold;">&gt;</span>
                    <span style="color:#0066ff; font-weight:bold;">@t</span>.<span style="color:#9900CC;">Label</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>: <span style="color:#0066ff; font-weight:bold;">@t</span>.<span style="color:#9900CC;">Field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
                <span style="color:#006600; font-weight:bold;">&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span>                                                      
            <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
&nbsp;
        <span style="color:#006600; font-weight:bold;">&lt;</span>fieldset id=<span style="color:#996600;">&quot;contactForm&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>    
&nbsp;
        <span style="color:#0066ff; font-weight:bold;">@builder</span>.<span style="color:#9900CC;">TemplateFor</span><span style="color:#006600; font-weight:bold;">&#40;</span> m <span style="color:#006600; font-weight:bold;">=&gt;</span> m.<span style="color:#9900CC;">Name</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#0066ff; font-weight:bold;">@builder</span>.<span style="color:#9900CC;">TemplateFor</span><span style="color:#006600; font-weight:bold;">&#40;</span> m <span style="color:#006600; font-weight:bold;">=&gt;</span> m.<span style="color:#9900CC;">Email</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
        <span style="color:#006600; font-weight:bold;">&lt;/</span>fieldset<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>Feel free to <a href="https://github.com/castleproject/Castle.MonoRail3/tree/master/src/Castle.Blade">give it a try</a>. </p>
<h1>MonoRail+++</h1>
<p>MonoRail&#8217;s 3 goal is based on our my experience and perception of the &#8220;state of the union&#8221; and trends. If I could put them in three simple statements: </p>
<p><strong>I&#8217;m mentally tired of crafting web sites despite huge functionality overlaps (combine/compose). I&#8217;m tired of REST being an afterthought to existing websites (rest support from the beginning). I&#8217;m tired of frameworks created by people without *actual* website building experience (frictionless).</strong></p>
<p>The goals/roadmap/value-proposition <a href="http://groups.google.com/group/castle-project-devel/browse_thread/thread/d8d3863f440c31eb/548bdfaaf8dd64a3?lnk=gst&#038;q=MR+proposition#548bdfaaf8dd64a3">were discussed</a> in the past in our development list. </p>
<ul>
<li>Since our underlying runtime (CLR) is keen on static typing then fully embrace it</li>
<li>Move forward: embrace HTML 5 </li>
<li>Simplify special render for different form factors</li>
<li>Strive for simplicity, but no simpler</li>
</ul>
<p>I&#8217;ll dive into what&#8217;s been done in practice to address each of the above bullets in upcoming blog posts. </p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/07/mr-3-update-castle-blade/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/07/mr-3-update-castle-blade/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Exposing extension methods in F#</title>
		<link>http://hammett.castleproject.org/index.php/2011/04/exposing-extension-methods-in-f/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/04/exposing-extension-methods-in-f/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 05:06:26 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=354</guid>
		<description><![CDATA[Thanks for Quora + Reflector + MSDN, I&#8217;ve figured out how to expose extension methods from F# Create a public module within a namespace Add the extension method as a function Decorate both the module and the function(s) with the ExtensionMethodAttribute namespace Castle.MonoRail &#160; &#91;&#60;System.Runtime.CompilerServices.ExtensionAttribute&#62;&#93; module public ExtensionMethods = &#160; open Castle.MonoRail.Routing open Castle.MonoRail.Hosting.Mvc &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks for <a href="http://www.quora.com/l/M1hDbSy8">Quora</a> + Reflector + MSDN, I&#8217;ve figured out how to expose extension methods from F#</p>
<ol>
<li>Create a public module within a namespace</li>
<li>Add the extension method as a function</li>
<li>Decorate both the module and the function(s) with the ExtensionMethodAttribute</li>
</ol>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow">
<span style="color: #0600FF; font-weight: bold;">namespace</span> Castle<span style="color: #008000;">.</span><span style="color: #0000FF;">MonoRail</span>
&nbsp;
<span style="color: #008000;">&#91;</span><span style="color: #008000;">&lt;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ExtensionAttribute</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#93;</span>
module <span style="color: #0600FF; font-weight: bold;">public</span> ExtensionMethods <span style="color: #008000;">=</span> 
&nbsp;
    open Castle<span style="color: #008000;">.</span><span style="color: #0000FF;">MonoRail</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Routing</span>
    open Castle<span style="color: #008000;">.</span><span style="color: #0000FF;">MonoRail</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Hosting</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Mvc</span>
&nbsp;
    <span style="color: #008000;">&#91;</span><span style="color: #008000;">&lt;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ExtensionAttribute</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#93;</span>
    let Match<span style="color: #008000;">&#40;</span>router<span style="color: #008000;">:</span>Router, path<span style="color: #008000;">:</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=</span> 
        router<span style="color: #008000;">.</span><span style="color: #0000FF;">Match</span><span style="color: #008000;">&#40;</span>path, MonoRailHandlerMediator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/04/exposing-extension-methods-in-f/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/04/exposing-extension-methods-in-f/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Loading contexts effectively</title>
		<link>http://hammett.castleproject.org/index.php/2011/03/using-loading-contexts-effectively/</link>
		<comments>http://hammett.castleproject.org/index.php/2011/03/using-loading-contexts-effectively/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:02:41 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Architecturing]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=352</guid>
		<description><![CDATA[Long long time ago I promised a few people in my twitter that someday Iâ€™d post somewhere a sample on how to deal with â€œdependency hellâ€. By that I mean something youâ€™ve probably experienced yourself. Suppose youâ€™re happily using log4net, and then you start using NHibernate which happens to use a different version of log4net. [...]]]></description>
			<content:encoded><![CDATA[<p>Long long time ago I promised a few people in my twitter that someday Iâ€™d post somewhere a sample on how to deal with â€œdependency hellâ€. </p>
<p>By that I mean something youâ€™ve probably experienced yourself. Suppose youâ€™re happily using log4net, and then you start using NHibernate which happens to use a different version of log4net. Hmmm. Easy. You can switch your own copy to the NHibernate uses. Then you add another dependency to your project, say SupperCoolWidget, and it happens to use yet another version of log4net. </p>
<p>You can rely on binding redirects, as long as youâ€™re damn sure the API surfaced touched by these projects havenâ€™t changed on the dependency (in this case log4net), otherwise youâ€™ll get exceptions in runtime (cannot find member). </p>
<p>IMHO itâ€™s especially problematic to rely on binding redirects because some code, somewhere, isnâ€™t used very often, and in some special circumstance it may try to use an API that isnâ€™t there. </p>
<p>log4net is an interesting example, but the problem applies to any scenario where you have common dependencies in different versions.</p>
<p>Looking at another camp â€“ Java in particular â€“ OSGi brought some interesting ideas to this very situation. There itâ€™s even worse since jars are way more loose than assemblies. OSGiâ€™s solution is to either have independent versioned <strong>bundles</strong> which your bundle may explicit say it depends upon, _or_ your bundle carries everything it needs to work. Multiple bundles can be loaded and executed in a single VM, and they are guarantee to not step on each others foot.</p>
<p>Javaâ€™s enabler to this magic is the ClassLoader. </p>
<p>In .NET there isnâ€™t a concrete equivalent of the Class loader, but we have a loader. And it has different contexts. In fact, as many as you want. The Load and LoadFrom contexts are the typical ones youâ€™re exposed to. More resources: <a href="http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx">Choosing a Binding Context</a> and <a href="http://blogs.msdn.com/b/suzcook/archive/0001/01/01/57248.aspx">LoadFile vs LoadFrom</a></p>
<p>By using a combination of the right loading context and the AssemblyResolve event, you can achieve the behavior of isolated silos loading the same assemblies (with different versions) in the same AppDomain.</p>
<p>I created a sample to demonstrate the idea and you take it from there. Iâ€™ve tried to minimize the concepts, so no MEF, no Windsor, and itâ€™s not a web app. The file structure is like the following</p>
<p><a href="http://hammett.castleproject.org/wp-content/uploads/2011/03/capture.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Capture" border="0" alt="Capture" src="http://hammett.castleproject.org/wp-content/uploads/2011/03/capture-thumb.png" width="242" height="244" /></a></p>
<p>The build folder contains the app, which doesnâ€™t do much:</p>
<p>  <pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> CustomBinder _binder = <span class="kwrd">new</span> CustomBinder();

<span class="kwrd">static</span> <span class="kwrd">void</span> Main()
{
    var curDir = AppDomain.CurrentDomain.BaseDirectory;

    <span class="rem">// Each module is loaded in its own isolated context</span>
    <span class="rem">// so they can have conflict dependencies and work</span>
    var modules = LoadModules(_binder, curDir);

    <span class="kwrd">foreach</span> (var module <span class="kwrd">in</span> modules)
    {
        Console.WriteLine(module);
    }
}</pre><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>So it loads â€œmodulesâ€ in a kind of late bound way, using a well-known contract: IModule. </p>
<p>Each module implementation depends on â€“ guess what â€“ log4net. But different versions of it. Each implementation of IModule looks pretty much the same, but the dependency version is quite different:</p>
<p><pre class="csharpcode"><span class="kwrd">namespace</span> FakeMod1
{
    <span class="kwrd">using</span> WellKnownContracts;

    <span class="kwrd">public</span> <span class="kwrd">class</span> Mod1Impl : IModule
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> log4net.ILog logger = log4net.LogManager.GetLogger(<span class="kwrd">typeof</span>(Mod1Impl));

        <span class="kwrd">public</span> Mod1Impl()
        {
            logger.Info(<span class="str">&quot;constructed&quot;</span>);
        }
    }
}

<span class="kwrd">namespace</span> FakeMod2
{
    <span class="kwrd">using</span> WellKnownContracts;

    <span class="kwrd">public</span> <span class="kwrd">class</span> Mod2Impl : IModule
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> log4net.ILog logger = log4net.LogManager.GetLogger(<span class="kwrd">typeof</span>(Mod2Impl));

        <span class="kwrd">public</span> Mod2Impl()
        {
            logger.Info(<span class="str">&quot;Mod2Impl constructed&quot;</span>);
        }
    }
}</pre><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>When we run the app we expect the following to happen</p>
<ul>
<li>module 1 is found</li>
<li>A logical context is created for it</li>
<li>Each dependency within the module 1 is satisfied within the boundary</li>
<li>module 2 is found</li>
<li>ditto ditto..</li>
</ul>
<p>Running the app and watching the debugger confirms the expected behavior:</p>
<p><font face="Courier New">&#8216;ParallelContexts.vshost.exe&#8217;: Loaded &#8216;ParallelContexts.exe&#8217;, Symbols loaded.<br />
    <br />&#8216;ParallelContexts.vshost.exe&#8217;: Loaded &#8216;WellKnownContracts.dll&#8217;, Symbols loaded.</font></p>
<p><font face="Courier New">&#8216;ParallelContexts.vshost.exe&#8217;: Loaded <font style="background-color: #ffff00">&#8216;modules\mod1\FakeMod1.dll&#8217;</font>, Symbols loaded.</p>
<p>&#8216;ParallelContexts.vshost.exe&#8217;: Loaded <font style="background-color: #ffff00">&#8216;modules\mod1\log4net.dll&#8217;</font></font></p>
<p><font face="Courier New">log4net:ERROR No appenders could be found for logger (FakeMod1.Mod1Impl).<br />
    <br />log4net:ERROR Please initialize the log4net system properly.</font></p>
<p><font face="Courier New">&#8216;ParallelContexts.vshost.exe&#8217;: Loaded <font style="background-color: #ffff00">&#8216;modules\mod2\FakeMod2.dll&#8217;</font>, Symbols loaded.</p>
<p>&#8216;ParallelContexts.vshost.exe&#8217;: Loaded <font style="background-color: #ffff00">&#8216;modules\mod2\log4net.dll&#8217;</font></font></p>
<p>Notice that WellKnownContracts.dll isnâ€™t loaded more than once, since it first loaded in the Load context, itâ€™s always found â€“ <em>Iâ€™m a bit unsure if this one is even probed after itâ€™s loaded for the first time</em>. </p>
<p>&#160;</p>
<h2>How it works?</h2>
<p>The code is simple. The class CustomBinder takes a â€œmodule folderâ€, and starts a new logical context for it. </p>
<p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> CustomBinder : IDisposable
{
    ...


    <span class="kwrd">public</span> BindingContext Add(<span class="kwrd">string</span> modFolder)
    {
        var ctx = <span class="kwrd">new</span> BindingContext(<span class="kwrd">this</span>);
        var files = Directory.GetFiles(modFolder);

        <span class="kwrd">string</span> entryPointFromManifest = <span class="kwrd">null</span>;

        <span class="kwrd">foreach</span> (var file <span class="kwrd">in</span> files)
        {
            <span class="rem">// manifest has an entry point which is the first type/assembly we load</span>
            <span class="rem">// this is just an optimization, so we dont have to load all assemblies found within a package/module</span>
            <span class="kwrd">if</span> (Path.GetFileName(file).Equals(<span class="str">&quot;manifest.xml&quot;</span>, StringComparison.InvariantCultureIgnoreCase))
            {
                entryPointFromManifest = GetEntryPointFromManifest(file);
                <span class="kwrd">continue</span>;
            }

            <span class="kwrd">if</span> (!file.EndsWith(<span class="str">&quot;.dll&quot;</span>)) <span class="kwrd">continue</span>;

            var name = AssemblyName.GetAssemblyName(file);
            ctx.AddAssemblyName(name.Name, file);
        }

        <span class="kwrd">if</span> (entryPointFromManifest != <span class="kwrd">null</span>)
        {
            <span class="kwrd">string</span>[] split = entryPointFromManifest.Split(<span class="str">','</span>);
            Debug.Assert(split.Length == 2);
            ctx.EntryPointTypeName = split[0];
            ctx.PreLoad(split[1].TrimStart());
        }

        <span class="kwrd">return</span> ctx;
    }</pre><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>Then, whenever the loader probes for an assembly, we use the â€œrequesting assemblyâ€ to bring the existing context back, and use it to load the right assembly. </p>
<p><pre class="csharpcode"><span class="kwrd">private</span> Assembly CurrentDomain_AssemblyResolve(<span class="kwrd">object</span> sender, ResolveEventArgs args)
{
    <span class="kwrd">if</span> (args.RequestingAssembly == <span class="kwrd">null</span>)
        <span class="kwrd">return</span> <span class="kwrd">null</span>;

    BindingContext ctx = GetBindingContext(args.RequestingAssembly);
    <span class="kwrd">if</span> (ctx == <span class="kwrd">null</span>) <span class="kwrd">return</span> <span class="kwrd">null</span>;

    Assembly assembly;
    <span class="kwrd">if</span> (ctx.TryGetAssembly(<span class="kwrd">new</span> AssemblyName(args.Name), <span class="kwrd">out</span> assembly))
    {
        <span class="kwrd">return</span> assembly;
    }

    <span class="kwrd">return</span> <span class="kwrd">null</span>;
}</pre><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>As I mentioned before, this is just a proof of concept that shows what is possible. The sky is the limit for modular/composable frameworks out there. Enjoy!</p>
<p><a href="http://dl.dropbox.com/u/12167075/ContextsSample.zip">Download sample</a></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2011/03/using-loading-contexts-effectively/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2011/03/using-loading-contexts-effectively/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MonoRail+++</title>
		<link>http://hammett.castleproject.org/index.php/2010/09/monorail/</link>
		<comments>http://hammett.castleproject.org/index.php/2010/09/monorail/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 06:30:57 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[Castle]]></category>
		<category><![CDATA[MonoRail]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=349</guid>
		<description><![CDATA[Itâ€™s been more than six years since the first prototype of MonoRail appeared on Castleâ€™s SVN repository. By then our website was hosted in a linux machine, the web server was Webrick, running a beta version of Rails, and had to be restarted once per day (at least) due to memory leaks. WebForms was the [...]]]></description>
			<content:encoded><![CDATA[<p>Itâ€™s been more than six years since the first prototype of MonoRail appeared on Castleâ€™s SVN repository. By then our website was hosted in a linux machine, the web server was Webrick, running a beta version of Rails, and had to be restarted once per day (at least) due to memory leaks. WebForms was the winner in the .net space, Struts the winner in the java space (unbelievable!), cocoon committers were toying with the idea of implementing continuations, probably inspired by <a href="http://www.seaside.st/">Seaside</a>.</p>
<p>Back then I was fresh back from London (now you know where Windsorâ€™s name came from), jobless, and entertaining with the idea of setting up a small software shop with Carlos and <a href="http://blogs.codehaus.org/people/bamboo/">Rodrigo</a>. One of the first challenges was to pick the technology to invest and potentially create a small product. Rodrigo was obviously biased towards .net with boo. I was playing with Ruby/Nitro. Carlos was inclined towards webforms with c#. We decided to pick one each, build somewhat similar and compare/contrast. AFAIK Rodrigo picked up some Java tech, Carlos chose boo, and I went with Rails. </p>
<p>I fell in love with Rails and became a strong advocate. However, as â€œour productâ€ grew in complexity, Rails â€“ by then â€“ didnâ€™t catch up. Big refactorings were hard due to the dynamic nature of Ruby, lack of unicode was a red flag for i18n, leaks and bad performance (couldnâ€™t get fastcgi to work on apache!). Also, the ecosystem, the libraries for dynamic image generation were badly maintained, if ever&#8230;</p>
<p>Thatâ€™s when I decided to combine the philosophy of Rails with the solid foundation of .net. By then it was called Castle on Rails.</p>
<p>Things have changed since then. MonoRail seems to have greatly inspired Microsoftâ€™s take on Model-View-Controller for the web. Mongrel, Merb and REST ascendance, a ton of great ideas continue to appear in the Ruby community. Same in a slower pace for other communities.</p>
<p>&#160;</p>
<h2>Web apps then and now</h2>
<p>While there was dynamicity in web apps six years ago, my perception is that today they have an aspect of multi-faceted apps. Html is just one of the multiple supported outputs of resource-based web sites. They expose services that can be used by your mother or another service. Twitter and Facebook are the greatest examples.</p>
<p>Bringing that to our work and especially the MS platform is somewhat puzzling. Who wants to maintain two entry points? Why a web app and a WCF Soap/Rest interface? Why itâ€™s so unnatural to deal with syndication on web apps?</p>
<p>&#160;</p>
<h2>The reuse dilemma</h2>
<p>Reuse has always been an OOP challenge. Many programming practices support designs that yield subsystems (size/complexity can vary) that can be reused. Not too many programmers embrace those programming practices, though. </p>
<p>As the complexity of web applications grow we see subteams owing subsystem with the same web application. Their technological choices are restricted by the common denominator. There ought to be a solution for this.</p>
<p>&#160;</p>
<h2>MonoRail 3.0</h2>
<p>This and other interesting discussions are taking place with the Castle team. I try hard to influence them over the big picture â€“ itâ€™s easy to get distract by what seems to be cool and interesting but deliver no value. In the last two months I drafted and propose a new enhanced design that should deal with the common challenges of web apps of today â€“ and hopefully of tomorrow! Today I completed a working prototype. </p>
<p>&#160;</p>
<h4>Minimal core</h4>
<p>The core is based on MicroKernel pattern. Itâ€™s a truly example of Open-Closed principle. It works by orchestrating a minimal set of extension points. Those are called primitives as they represent core abstract concepts.</p>
<p>The core is split into three architecture layers:</p>
<p><b>Layer 1: ASP.NET core augmentation</b></p>
<p>The layer 1 replaces the HttpHandler and HttpModule in ASP.NET with composable equivalents. You can then implement a new â€œhandlerâ€ that has â€œdependenciesâ€, and be sure that those will be satisfied.</p>
<p><b>Layer 2: Orchestrator</b></p>
<p>Layer 2 defines a minimal set of primitives and pipeline execution process. It establishes the minimal policy (behavior) but does not make assumptions over the implementation â€“ remember the Dependency Inversion Principle?</p>
<p><b>Layer 3: Model-View-Controller</b></p>
<p>Finally, the third layer is an implementation of layer 2 that exposes the common behavior of Model-View-Controller we all know and love. It also exposes extension points, such as an execution sink for controller execution. </p>
<p>&#160;</p>
<h4>Side-by-side extensions</h4>
<p>Windsor turned out to be successful because it delivered a rich extensibility mechanism and a minimal but useful combination of default behaviors. MonoRail 3 is built with the same principles. In fact, its Model-View-Controller capabilities are just one implementation over a set of â€œprimitiveâ€ contracts. Behavior can be modified, added or removed by using a small set of extension points. </p>
<p>The design supports side-by-side extensions, which means that extensions do not replace one-another, but instead are always additive. For example, I can have a WindsorIntegration and AutofacIntegration running at the same time. I can add to the mix Razor View Engine and IronRuby support. Not a single line of configuration code or xml.</p>
<p>&#160;</p>
<h4>Composition by default, even in your code</h4>
<p>Yes, you can turn off or replace it, but by default your app will have an IoC Container (well, MEF) composing your controllers. The composition is not limited to your types, in fact, you can express dependencies over framework components and request level objects. </p>
<h4>Maximized simplicity</h4>
<p>The following is a valid controller:</p>
<p>  <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> ProductsController
{
    <span class="kwrd">public</span> ActionResult Index()
    {
        var products = <span class="rem">// fetch list</span>
        <span class="kwrd">return</span> <span class="kwrd">new</span> ViewResult() { Model = products };
    }

    [RespondTo(ContentType.Html|ContentType.Xml|ContentType.JSon)]
    <span class="kwrd">public</span> Product View(<span class="kwrd">int</span> id)
    {
        var product = <span class="rem">// fetch by id</span>
        
        <span class="kwrd">if</span> (product == <span class="kwrd">null</span>)
            <span class="kwrd">throw</span> <span class="kwrd">new</span> HttpException(404, <span class="str">&quot;product not found&quot;</span>);
            
        <span class="kwrd">return</span> product;
    }
    
    <span class="kwrd">public</span> Product New()
    {
        <span class="kwrd">return</span> <span class="kwrd">new</span> Product();
    }

    <span class="kwrd">public</span> ActionResult Create(Product product)
    {
        <span class="rem">// pretend to save</span>
        var product = <span class="kwrd">new</span> Product();
        
        <span class="kwrd">return</span> RespondTo( format =&gt; 
            format.Model(product).
              Html().
              Xml( <span class="kwrd">new</span> ViewResult(<span class="str">&quot;create.xml&quot;</span>) ).
              Json()
        );
    }
    
}</pre><br />
<style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>If access to some response, request (or similar) objects are necessary, no worry, you have two options: use the Controller base class or specify the dependencies in your constructor. </p>
<h4>Powered by MEF</h4>
<p>One of my goals is to demonstrate how MEF can be used to enhance your frameworks, instead of just your applications. By using MEF I could easily skip any â€œregistrationâ€ step usually required by typical IoC Containers. I can also discover extensions easily in runtime without extra code.</p>
<hr />
<p><b>Where/When?</b></p>
<p>I&#8217;m planning to release a first drop later this week. Note I&#8217;m kinda extra busy as I&#8217;m getting married next weekend, but watch out for a preview drop. </p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2010/09/monorail/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2010/09/monorail/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>The curse of knowledge</title>
		<link>http://hammett.castleproject.org/index.php/2010/05/the-curse-of-knowledge/</link>
		<comments>http://hammett.castleproject.org/index.php/2010/05/the-curse-of-knowledge/#comments</comments>
		<pubDate>Mon, 31 May 2010 05:45:31 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=348</guid>
		<description><![CDATA[While reading Made to Stick I had to stop to appreciate the epiphany of this realization: The curse of knowledge is so real and concrete. I find myself having real trouble explaining things that are obvious to me. Teaching the benefits of good design, IoC Containers, Composition vs Inheritance and what is common about enterprise [...]]]></description>
			<content:encoded><![CDATA[<p>While reading Made to Stick I had to stop to appreciate the epiphany of this realization: The curse of knowledge is so real and concrete. I find myself having real trouble explaining things that are obvious to me. Teaching the benefits of good design, IoC Containers, Composition vs Inheritance and what is common about enterprise kinda of development as opposed to other types are just extremely challenging. </p>
<blockquote><p>People tend to think that having a great idea is enough, and they think the communication part will come naturally. We are in deep denial about the difficulty of getting a thought out of our own heads and into the heads of others. Itâ€™s just not true that, â€œIf you think it, it will stick.â€</p>
<p>And that brings us to the villain of our book: The Curse of Knowledge. Lots of research in economics and psychology shows that when we know something, it becomes hard for us to imagine not knowing it. As a result, we become lousy communicators. Think of a lawyer who canâ€™t give you a straight, comprehensible answer to a legal question. His vast knowledge and experience renders him unable to fathom how little you know. So when he talks to you, he talks in abstractions that you canâ€™t follow. And weâ€™re all like the lawyer in our own domain of expertise.</p>
</blockquote>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2010/05/the-curse-of-knowledge/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2010/05/the-curse-of-knowledge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alive and well</title>
		<link>http://hammett.castleproject.org/index.php/2010/05/alive-and-well/</link>
		<comments>http://hammett.castleproject.org/index.php/2010/05/alive-and-well/#comments</comments>
		<pubDate>Thu, 06 May 2010 20:51:40 +0000</pubDate>
		<dc:creator>hammett</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hammett.castleproject.org/?p=347</guid>
		<description><![CDATA[Wow, I thought I need to post something on this blog before the PHP code that runs it gets stale. Still alive, still working for Microsoft, but a few months ago our MEF team was merged into the Common Language Runtime (CLR) team. The CLR teams owns all the low level stuff: execution engine, JIT, [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, I thought I need to post something on this blog before the PHP code that runs it gets stale. </p>
<p>Still alive, still working for Microsoft, but a few months ago our MEF team was merged into the Common Language Runtime (CLR) team. The CLR teams owns all the low level stuff: execution engine, JIT, GC, and some not so low level things like the Base class library (BCL) and security model. So if you have any complains on any of these things let me know and I&#8217;ll ensure you I&#8217;ll forward to the appropriate person and make sure I get a reply :-)</p>
<p>While I&#8217;m still working on MEF I also managed to get involved in some new CLR stuff for the upcoming version. Early days, so nothing to talk about yet.</p>
<h2>MEF updates</h2>
<p>I&#8217;m working with ASP.NET MVC team to have MEF integrated with the next MVC version. There are a lot of constraints that won&#8217;t allow us to optimize a lot of the experience, but things should change soon. </p>
<p>I&#8217;ve managed to put together a sample depicting MEF integration with WebForms. I&#8217;ve used ControlBuilders to change the generated code to use MEF&#8217;s container to instantiate controls. Let me know how you like the approach. We&#8217;re considering productizing it, but we need to measure the interest level first. Would that be useful to you?</p>
<p>Finally, among other things we&#8217;ve been exploring, componentizing our container implementation is one of my goals. Simplifying some common tasks and APIs is another. For those who are not really fond of MEF&#8217;s attributes I&#8217;ve prototyped a convention-based registration API. Will blog about it soon. </p>
<h2>Castle updates</h2>
<p>So the Castle community really impressed me. They released a bunch of stuff and are managing to introduce loads of cool features. </p>
<h2>Other stuff</h2>
<p>iPad: being an owner of an iPhone and MacBook Pro I see absolute no reason to have an iPad. My standard reply when the subject comes up is &#8216;I have an iPhone, which is the compact version of the iPad&#8217;. Sorry Steve Jobs, you won&#8217;t grab my $ for this one.</p>
<p>MS Courier: if you&#8217;ve been under a rock for the past year, go and check the <a href="http://www.youtube.com/watch?v=UmIgNfp-MdI">Courier</a>. It was canceled a few weeks back by MS. There was a short interview available to us on why this happened, but it wasn&#8217;t very convincing. I just truly hope they come up with something even better, and real soon. </p>
<p>Windows Phone 7: on the other hand, everybody here is excited about the new phone. Some (lucky!) few ones are already playing with prototypes. Did we get it right this time? Time will tell. </p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=137478926323901&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://hammett.castleproject.org/index.php/2010/05/alive-and-well/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://hammett.castleproject.org/index.php/2010/05/alive-and-well/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

