<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Chris van de Steeg</title>
	
	<link>http://www.chrisvandesteeg.nl</link>
	<description>What's practical is logical</description>
	<lastBuildDate>Tue, 28 Feb 2012 20:27:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/chrisvandesteeg" /><feedburner:info uri="chrisvandesteeg" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><item>
		<title>Sitecore MVC</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/BlZaud3I7R8/</link>
		<comments>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 20:57:15 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=281</guid>
		<description><![CDATA[January 1st I started my new Job at eFocus, a full service internet company, at the department specialized in Sitecore development. I’d never worked with Sitecore before, so it was a complete new experience. Since I love the ASP.NET MVC way of development, I started looking if there was an option to use it for [...]]]></description>
			<content:encoded><![CDATA[<p>January 1st I started my new Job at <a href="http://www.efocus.nl" target="_blank">eFocus</a>, a full service internet company, at the department specialized in Sitecore development. I’d never worked with Sitecore before, so it was a complete new experience. Since I love the ASP.NET MVC way of development, I started looking if there was an option to use it for Sitecore development. Unfortunately I did not find any community effort to do so, except for blog posts on how to use Sitecore and an MVC project side-by-side. So I decided to try to create my own solution, since I would then have something fun to do while getting to know the ins and outs of Sitecore, something I felt obliged to do anyway.</p>
<p>In this blog post I&#8217;ll show you how to install and use my end-result of this proof of concept. In a follow-up, I&#8217;ll create a sample application with it. This first version is really just that: a proof of concept, just showing that it works. For example, this version includes a simple valueprovider for binding sitecore items to a model, but this is far from optimal. When creating a sample application, I’ll also be digging into modelbinding and other issues that’ll show up when creating an application. Perhaps I’ll conclude that its better to use something like <a href="http://trac.sitecore.net/CustomItemGenerator#" target="_blank">CustomItem generator</a> or <a href="http://www.glass.lu/" target="_blank">the glass project</a> and wrap one of those in a modelbinder, we’ll see (shoot your opinion about that in the comments!). I also only tested this on Sitecore 6.4, so it’ll probably only work on that version and up.</p>
<p>Now, let’s go to the code! To get started, open an existing Sitecore project (or create a new one) in Visual Studio. Now add the NuGet package BoC.Sitecore.MvcApp either through the package manager console or through tools-&gt;library package manager-&gt;Manage NuGet Packages for Solution&#8230;</p>
<p><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="VerySimpleWebsite - Manage NuGet Packages_2012-02-28_18-36-28" border="0" alt="VerySimpleWebsite - Manage NuGet Packages_2012-02-28_18-36-28" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/VerySimpleWebsite-Manage-NuGet-Packages_2012-02-28_18-36-28.png" width="904" height="604" /></p>
<p>The Sitecore Mvc starter app is the version I’ll use for this blog-post: it will add a basic mvc project to your solution to get started with. The other one (BoC.Sitecore.Mvc) will just add the dll + a config file to your current project, use this one if you want to set up your own Mvc project without any starting point.</p>
<p>Once you’ve installed the package, a new project named ‘yourproject’.mvcapp is added to your solution:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_18-40-50" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_18-40-50" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_18-40-50.png" width="290" height="504" /></p>
<p>This is an empty ASP.NET MVC3 Razor project, with some stuff removed. The default web.config is removed, since we’ll have to use a modified version of Sitecore’s web.config and the account-stuff has been removed. As you can see, a default HomeController has been added, a default view and a default model (ItemView). Now, to see if BoC.Sitecore.Mvc works, let’s build the solution and open up the sitecore shell. Once logged in to your Sitecore shell, expand the tree items /sitecore/Layout and /sitecore/Layout/Layouts. You’ll see that underneath both, a new folder is added named ‘MVC Actions’. It’s in two places since you can use your MVC Actions both as Layout or as a rendering, more on that later.</p>
<p><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="Sitecore - Windows Internet Explorer_2012-02-28_19-02-43" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_19-02-43" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_19-02-43.png" width="247" height="447" /></p>
<p>Let’s see what the action and view for Home/Index looks like, so we can now what to expect to see when we try to load them in sitecore. The action itself looks very simple:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_19-09-36" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-09-36" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-09-36.png" width="414" height="163" /></p>
<p>It expects an item of type ItemView and just passes that on to the view. As mentioned earlier, I added a simple valueprovider that will try to resolve any parameter named “item” with field-values from the current sitecore item (the current sitecore item by default is the context.item, unless you provided a datasource for the rendering). The model by default only includes the property DisplayName of the type RenderingString:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_19-14-05" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-14-05" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-14-05.png" width="486" height="105" /></p>
<p>RenderingString is a special type added by BoC.Sitecore.Mvc : it will call RenderField when outputted in html so you can use the page editor. You could also change this to ‘public string DisplayName {get; set; }’ to have it filled with the normal string value. Since DisplayName is not editable in the page editor, and thus we cannot see the difference between RenderingString and normal String, let’s change this property to Title like so:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_19-19-04" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-19-04" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-19-04.png" width="428" height="85" /></p>
<p>In our case we’ll use the ‘Sample Item’ template from the default setup, which has a Title field. If your item does not have a Title field, you’ll have to pick some other field name of course. </p>
<p>Now, open up the view in Views/Home/Index.cshtml: </p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_20-05-05" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-05-05" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-05-05.png" width="314" height="50" /></p>
<p>The view still uses DisplayName, so we have to change that as well:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_20-08-02" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-08-02" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-08-02.png" width="313" height="49" /></p>
<p>When the view will be fully rendered (thus not through a RenderChildAction), the view uses the ‘masterpage’ Views/Shared/_Layout.cshtml:</p>
<p><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="emptysite - Microsoft Visual Studio_2012-02-28_20-14-09" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-14-09" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-14-09.png" width="886" height="622" /></p>
<p>As you can see there is a special HtmlHelper extension used here: @Html.RenderPlaceholder(“main”) which is the equivalent of &lt;sc:placeholder Key=”main” runat=”server” /&gt; for the aspx version.</p>
<p>Now, compile your changes, and go back to the sitecore shell. Underneath the Homepage, add a new Sample Item template called ‘My new sample item’ and click the ‘Layout Details’ button in the ‘Presentation’ Ribbon.&#160; In the dialog that opens, click on ‘edit’.</p>
<p><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="Sitecore MVC - Windows Live Writer_2012-02-28_20-11-17" border="0" alt="Sitecore MVC - Windows Live Writer_2012-02-28_20-11-17" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-MVC-Windows-Live-Writer_2012-02-28_20-11-17.png" width="833" height="631" /></p>
<p>In the next dialog, click on the layout to pick the MVC Actions / Home / Index layout</p>
<p><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="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-20-37" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-20-37" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-20-37.png" width="513" height="633" /></p>
<p>Now, save all modifications by click ‘OK’ twice.</p>
<p>Now in the ribbon presentation, click on the ‘preview’ button to see our new page.</p>
<p><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="Sitecore - Windows Internet Explorer_2012-02-28_20-26-29" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_20-26-29" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_20-26-29.png" width="1099" height="452" /></p>
<p>And there it is! Our MVC rendered sitecore item. The page still holds all the other renderings from the original Sample Item template including the nested <em>Sample Sublayout.ascx</em> the <em>Sample Inner Sublayout.ascx </em>and the <em>sample rendering.xslt. </em>So now we have an MVC rendered razor layout, holding asp.net usercontrols with an xslt rendering! You can mix-and-match those all together, how cool is that! </p>
<p>The item’s title is displayed twice, since our ‘Layout’ renders the title also, remember (the Home/Index.cshtml ouputs the title, and we’ve picked that as our Layout for the sitecore item). To see that the page editor also still works (even for the razor code), click on the ‘page editor’ button in the ‘Publish’ ribbon.</p>
<p><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="httplocalhost56325sc_mode=edit&amp;sc_itemid=%7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35" border="0" alt="httplocalhost56325sc_mode=edit&amp;sc_itemid=%7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/httplocalhost56325sc_modeeditsc_itemid7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35.png" width="636" height="588" /></p>
<p>Modify the fields, add some extra renderings, it all still works. To show off an extra mix-and-match, now let’s also add our action as rendering to the existing asp.net based homepage.</p>
<p>Click on the homepage-treeitem and click on the ‘Layout details’ button on the ‘Presentation’ ribbon. In the popup dialog, click on ‘edit’ and then, in the next popup dialog, click on controls.</p>
<p><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="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-39-30" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-39-30" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-39-30.png" width="497" height="269" /></p>
<p>Now, click the add button. In the next popup dialog, select MVCActions/Home/Index and add it to placeholder ‘/main/centercolumn/content’</p>
<p><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="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-41-12" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-41-12" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-41-12.png" width="409" height="395" /></p>
<p>Click on select, and then twice on OK to save this new addition. Now, on our preview pane, we see an extra Title appear!</p>
<p><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="Sitecore - Windows Internet Explorer_2012-02-28_20-44-43" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_20-44-43" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_20-44-43.png" width="525" height="472" /></p>
<p>This is our Views/Home/Index.cshtml ! Since the action is now added to the page as a rendering instead of being used as a layout, the /Views/Shared/_Layout.cshtml is not used. This is because this action is now being rendered by calling MVC’s RenderChildAction. Child actions never have a layout.</p>
<p>Now just go ahead and do some mixing of different options for yourself, you could try a different viewengine (aspx, spark viewengine) for example, works just fine. A little extra nice-to-know is that you can add a DescriptionAttribute to your controllers and/or actions to have them show up differently in sitecore. ({0} is thereby replaced with the original name).</p>
<p>I hope you’ll all enjoy playing with MVC within Sitecore and get some great ideas about it while you’re at it. Please leave all your great ideas and suggestions in the comments.</p>
<p>If you want to checkout the source, you can find that at github: <a title="https://github.com/csteeg/BoC.Sitecore.MVC" href="http://github.com/csteeg/BoC.Sitecore.MVC">http://github.com/csteeg/BoC.Sitecore.MVC</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=BlZaud3I7R8:XW2ZjX4vZWk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/</feedburner:origLink></item>
		<item>
		<title>Compile your asp.net mvc Razor views into a seperate dll</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/hLzcukfjB2U/</link>
		<comments>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 16:05:40 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=242</guid>
		<description><![CDATA[Inspired by David Ebbo’s blog post ‘Turn your Razor helpers into reusable libraries’ I wanted to be able to embed compiled Razor views in a dll. This would allow for easy distribution of asp.net mvc ‘modules’ that have their default views embedded, but allowing you to place files in your ‘views’ folder to override those [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://blogs.msdn.com/b/davidebb/">David Ebbo</a>’s blog post ‘<a href="http://blogs.msdn.com/b/davidebb/archive/2010/10/27/turn-your-razor-helpers-into-reusable-libraries.aspx">Turn your Razor helpers into reusable libraries</a>’ I wanted to be able to embed compiled Razor views in a dll. This would allow for easy distribution of asp.net mvc ‘modules’ that have their default views embedded, but allowing you to place files in your ‘views’ folder to override those default views. </p>
<p>To generate the c# code for the views, I just started out with David Ebbo’s single file generator and modified it to generate views instead of helpers only. To do this, there had to be a WebRazorHostFactory that knew about all the mvc stuff (what dll’s to reference, what namespaces to use, etc) .I could either choose to include all that information statically in the code, or I could look for a web.config in the same project and let the WebRazorHostFactory use that config. I chose the latter option, so that everyone can easily change the WebRazorHostFactory behavior&#160; by adding a web.config file to their project.</p>
<p>Next, I started figuring out how the PageVirtualPathAttribute inside System.Web.Webpages.dll is used by Microsoft. I found out that it is used when you call ApplicationPart.Register and after that call, there’s not much you can use of this functionality without some heavy reflection. I know it’s the wrong path to choose, but did it anyway. I ended up creating a ViewEngine calling into ApplicationPart’s internal methods to output compiled views. It worked, but I didn’t like it much: there had to be a better way.</p>
<p>I then tried if I could hook into the BuildManager stuff that asp.net mvc uses to generate the views. It was actually much easier then expected, now why didn’t I go on that path the first time!</p>
<p>I ended up creating </p>
<ul>
<li>a CompiledRazorBuildProvider, which inherits from the default RazorBuildProvider,</li>
<li>a CompiledVirtualPathProvider which returns a CompiledVirtualFile if it decides that a compiled view should be used</li>
<li>and a ApplicationPartRegistry, which registers which compiled views are available.</li>
</ul>
<p>To view the source, head over to </p>
<ul>
<li><a href="https://github.com/csteeg/BoC/tree/master/Src/Commons.Web.PrecompiledViews/">https://github.com/csteeg/BoC/tree/master/Src/Commons.Web.PrecompiledViews/</a> – for the classes mentioned</li>
<li><a href="https://github.com/csteeg/BoC/tree/master/Src/RazorSingleFileGenerator/">https://github.com/csteeg/BoC/tree/master/Src/RazorSingleFileGenerator/</a> – for David Ebbo’s modfied file generator</li>
</ul>
<p>To just get started without viewing the source, read on, I will explain step by step how to use this library with some screenshots.</p>
<p>If you have improvements, fork the project on GitHub and let me know! If you have suggestions for improvement, just drop it in the comments.</p>
<h3>Step 1: Install the FileGenerator</h3>
<p>Download and install the Visual Studio extension: <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/f28290ce-d987-4f91-b034-707031e10ce6/file/39295/0/RazorSingleFileGenerator.vsix">http://visualstudiogallery.msdn.microsoft.com/en-us/f28290ce-d987-4f91-b034-707031e10ce6/file/39295/0/RazorSingleFileGenerator.vsix</a></p>
<h2></h2>
<h3>Step 2: Create new mvc project</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb.png" width="959" height="664" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image1.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb1.png" width="651" height="584" /></a></p>
<h3></h3>
<h3>Step 3: Add a class library to hold the views</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb2.png" width="539" height="566" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb3.png" width="959" height="664" /></a></p>
<h3>Step 4: Cut your Models &amp; Views folders</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb7.png" width="674" height="535" /></a></p>
<h3></h3>
<h3>Step 5: Paste them into the just created Class Library</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb8.png" width="629" height="466" /></a></p>
<h3>Step 6: Copy the website’s web.config file</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image9.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="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb9.png" width="643" height="287" /></a></p>
<h3>Step 7: Paste that web.config file into the class library</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb10.png" width="701" height="704" /></a></p>
<h3>Step 8: Select all your .cshtml files in the class library and set the Custom Tool to ‘MvcRazorClassGenerator’</h3>
<p><em>Does anyone have a suggestion on improving this step??</em></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb6.png" width="654" height="391" /></a></p>
<h3>Step 9: Build your class library</h3>
<h3>Step 10: Add your class library to the references of the web application</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb11.png" width="367" height="171" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image12.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb12.png" width="565" height="450" /></a></p>
<h3>Step 11: Add ‘Commons.web.mvc.precompiledviews.dll’ as a reference to your website</h3>
<p><em>this dll is copied to the class library’s output folder (in this case ../EmbeddedViews/bin/debug&#8217;)</em></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image13.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="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb13.png" width="565" height="450" /></a></p>
<h3>Step 12: Register your views by adding a line to the application_start in global.asax.cs</h3>
<h3></h3>
<h3></h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image14.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb14.png" width="456" height="232" /></a></p>
<h3></h3>
<h3>Step 13: Run your website!</h3>
<p>Now, you will see the normal default website, even though there aren’t any views in your website path!</p>
<p>If you wish to override some views, just create the normal folders (eg /Views/Home) and add your views there, but don’t forget to copy back the deleted /Views/web.config back into your project then!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=hLzcukfjB2U:O0AbPSW16bs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/</feedburner:origLink></item>
		<item>
		<title>HappyBirthday app – Vodafone App Star Country winner</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/mex4vZOs2RQ/</link>
		<comments>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/#comments</comments>
		<pubDate>Wed, 05 May 2010 20:25:27 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[vf360]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=217</guid>
		<description><![CDATA[I&#8217;m very (very!) happy to inform you all that my mobile app HappyBirthday! has won the 1st price at the Vodafone AppStar competition for the Netherlands. This also means, the app is now 1 of the eight apps in the the grand final! The first price of the finals is another &#8364; 75.000 !! So [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very (very!) happy to inform you all that my mobile app <a href="http://www.chrisvandesteeg.nl/mobile-apps/happybirthday">HappyBirthday!</a> has won the 1st price at the Vodafone AppStar competition for the Netherlands. This also means, the app is now 1 of the eight apps in the the grand final! The first price of the finals is another &euro; 75.000 !!<br />
So I kindly ask you to all go vote at <a href="http://widget.developer.vodafone.com/nl/appstar/entries/671/voter/new">the Vodafone App Star website</a> and get me that first price! <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>HappyBirthday is an app for the <a href="http://360.com">Vodafone 360</a> platform and helps you to never forget a birthday again.<br />
You can read more about the app at <a href="http://www.chrisvandesteeg.nl/mobile-apps/happybirthday">the details page of HappyBirthday!</a></p>
<p>The <a href="http://360.com">Vodafone 360 platform</a> is a new internet service for your mobile, PC and Mac. It brings your phone, email, chat and social network contacts together in one placeand runs on many many phones. You don&#8217;t need to have a vodafone account to join 360, anyone can join at <a href="http://360.com">http://360.com</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=mex4vZOs2RQ:X8zVpIHKvzE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/UoAhXMvngZU/</link>
		<comments>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 13:28:13 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[nhiberntate]]></category>
		<category><![CDATA[RiaServices]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=91</guid>
		<description><![CDATA[I’ve been playing with RIAServices and DynamicData lately, and managed to combine these with NHibernate as ORM in an ASP.NET MVC project. For this project the following (extensive) list of libraries is used (all these libraries are included in the download): MS ASP.NET Mvc 1.0 Microsoft .NET RIA Services July 2009 Preview NHibernate 2.1.0CR1 NHibernate [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been playing with RIAServices and DynamicData lately, and managed to combine these with NHibernate as ORM in an ASP.NET MVC project.</p>
<p>For this project the following (extensive) list of libraries is used (all these libraries are included in the download):</p>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=144444" target="_blank">MS ASP.NET Mvc 1.0</a> </li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=144609" target="_blank">Microsoft .NET RIA Services July 2009 Preview</a> </li>
<li><a href="http://nhforge.org/blogs/nhibernate/archive/2009/07/05/good-morning-nhibernate-2-1-0cr1.aspx" target="_blank">NHibernate 2.1.0CR1</a> </li>
<li><a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Linq/" target="_blank">NHibernate Linq</a> (latest trunk version) </li>
<li><a href="http://fluentnhibernate.org/" target="_blank">FluentNhibernate</a> (latest trunk version, patched to work with NHibernate 2.1.0CR1) </li>
<li><a href="http://www.codeplex.com/unity" target="_blank">MS Unity 1.2</a> </li>
<li><a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18803" target="_blank">ASP.NET Dynamic Data MVC Preview</a> (since this project is pretty old, I had to modify it quite a bit, the source is included in the download) </li>
<li>I used <a href="http://blog.wekeroad.com/blog/make-visual-studio-generate-your-repository/" target="_blank">Rob Conery’s t4 templates</a> as the base to generate entities from the database. </li>
</ul>
<p>Besides using these libraries, I copied some code snippits from the <a href="http://www.codeplex.com/Kigg" target="_blank">Kigg</a> project, which has quite a nice codebase!</p>
<p>In the first part of this serie, I’ll show you how you can use these libraries along with my own code to scaffold the entire Northwind database in an mvc project. It’ll be totally hassle-free, I promise! It will generate classes from the database-schema and I will also show you how to override the default generated domainservices and repositories (yes, those are generated at runtime if you don’t specify your own!).</p>
<p>In the upcoming parts, I will add client-side validation and some ajax-love to the scaffold pages. In one of those parts I’ll also explain how my code works, and what it does. I’m also thinking about showing how to replace some parts of the library, since it’s very pluggable. I could for example replace the persistencelayer with Linq-to-Sql or replace the Depency part with StructureMap.</p>
<p>Although this sample shows you how to use an existing database, it would ofcourse be best if you could use the Model-first approach! Luckely nHibernate makes this very simple as well. If you create the entity files in your project and have them inherited from BaseEntity, all you have to do is add this line to your Application_Start:</p>
<p>new SchemaUpdate(IoC.Resolve&lt;Configuration&gt;).Execute(true, true);</p>
<p>Your database schema will be automatically updated if you change anything to your Model.</p>
<p>You can watch the screencast <a href="http://www.screentoaster.com/watch/stVUJXRExIR11XRF5YXFJbUVVc" target="_blank">here</a> and download the sample + dll’s <a href="http://code.google.com/p/webdotnet/downloads/list" target="_blank">here</a></p>
<p>&#160;</p>
<p> <object id='stVUJXRExIR11XRF5YXFJbUVVc' width='600' height='400' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name="movie" value="http://www.screentoaster.com/swf/STPlayer.swf" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="flashvars" value="video=stVUJXRExIR11XRF5YXFJbUVVc" /></object>
<p>For the next screencast, I’ll by a mic so I don’t have to subtitle it <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=UoAhXMvngZU:_EqeD7bIWcw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/</feedburner:origLink></item>
		<item>
		<title>Making Unity work more like the others</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/SqSo6RLpLUk/</link>
		<comments>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 18:53:58 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=80</guid>
		<description><![CDATA[I love MS Unity as an IoC container, it has some great features. Though I found it to function incorrectly at two points (it&#8217;s not that the path chosen by the Unity team is incorrect, I just want/excpect it to act differently). The first thing that bothered me was the fact that Unity throws an [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://www.codeplex.com/unity" target="_blank">MS Unity</a> as an IoC container, it has some great features. Though I found it to function incorrectly at two points (it&#8217;s not that the path chosen by the Unity team is incorrect, I just want/excpect it to act differently).  </p>
<p> The first thing that bothered me was the fact that Unity throws an exception when Resolve&lt;T&gt; is not able to resolve the given type: I’d prefer it to return null instead, hence most containers do that. The second, even more irritating point, was that ResolveAll&lt;T&gt; only returned the named instances/types instead of all registered types. In fact, Unity overwrites the default registration if your register a type multiple times. Eg:</p>
<pre class="c-sharp" name="code">
Container.Register&lt;IMyInterFace, MyClass1&gt;();
Container.Register&lt;IMyInterFace, MyClass2&gt;();
</pre>
<p>would cause the MyClass1 registration to be removed. I’d like the MyClass1 to remain the default registration, and have ResolveAll&lt;IMyInterface&gt;() return both. I’m happy to tell you that it can be done!</p>
<p>When using an IoC container, it’s good practice to access it’s features through a generic wrapper class. For my projects, I use the wrapper from the <a href="http://www.codeplex.com/Kigg" target="_blank">Kigg</a> source code. If you access the container through a wrapper after you configured your container, it&#8217;ll be easy to replace it with a different container in the future.</p>
<p>My wrapper class looks like this:</p>
<pre class="c-sharp" name="code">
public class UnityDependencyResolver : IDependencyResolver
{
    private readonly IUnityContainer container;

    public UnityDependencyResolver() : this(new UnityContainer())
    {
        var configuration = (UnityConfigurationSection) ConfigurationManager.GetSection("unity");
        if (configuration != null)
            configuration.Containers.Default.Configure(container);
    }

    public UnityDependencyResolver(IUnityContainer container)
    {
        Check.Argument.IsNotNull(container, "container");

        this.container = container;
        this.container.AddExtension(new TypeTrackingExtension());
        this.container.RegisterInstance&lt;IUnityContainer&gt;(container);
        this.container.RegisterInstance&lt;IDependencyResolver&gt;(this);
    }

    public IUnityContainer Container { get { return container; } }

    public void RegisterInstance&lt;T&gt;(T instance)
    {
        Check.Argument.IsNotNull(instance, "instance");

        container.RegisterInstance(instance);
    }

    public void RegisterType&lt;TFrom, TTo&gt;() where TTo : TFrom
    {
        container.RegisterType&lt;TFrom, TTo&gt;();
    }

    public void RegisterType(Type from, Type to)
    {
        Check.Argument.IsNotNull(from, "from");
        Check.Argument.IsNotNull(to, "to");

        container.RegisterType(from, to);
    }

    public void Inject&lt;T&gt;(T existing)
    {
        Check.Argument.IsNotNull(existing, "existing");

        container.BuildUp(existing);
    }

    public object Resolve(Type type)
    {
        Check.Argument.IsNotNull(type, "type");
        if (container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type))
        {
            return container.Resolve(type);
        }
        else
        {
            return null;
        }
    }

    public object Resolve(Type type, string name)
    {
        Check.Argument.IsNotNull(type, "type");
        if (Container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type, name))
        {
            return container.Resolve(type, name);
        }
        else
        {
            return null;
        }
    }

    public T Resolve&lt;T&gt;()
    {
        return (T) Resolve(typeof(T));
    }

    public T Resolve&lt;T&gt;(string name)
    {
        Check.Argument.IsNotEmpty(name, "name");
        return (T) Resolve(typeof(T), name);
    }

    public IEnumerable&lt;T&gt; ResolveAll&lt;T&gt;()
    {
        var namedInstances = container.ResolveAll&lt;T&gt;();
        var unnamedInstance = default(T);

        try
        {
            unnamedInstance = container.Resolve&lt;T&gt;();
        }
        catch (ResolutionFailedException)
        {
            //When default instance is missing
        }

        if (Equals(unnamedInstance, default(T)))
        {
            return namedInstances;
        }

        return new ReadOnlyCollection&lt;T&gt;(new List&lt;T&gt;(namedInstances) { unnamedInstance });
    }

    ~UnityDependencyResolver()
    {
        Dispose(false);
    }
    public void Dispose()
    {
        Dispose(true);
    }
    protected void Dispose(bool disposing)
    {
        if (disposing)
        {
            container.Dispose();
        }
    }
}
</pre>
<p>Though most methods are just direct wrappers for accessing the container itself, there are a few extra’s. For one, there’s the ResolveAll&lt;T&gt; method that returns both named and unnamed instances instead of only the named instances, that’s one problem fixed.</p>
<p>Secondly, you can see the Resolve methods use</p>
<p>if (Container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type, name))</p>
<p>It uses an UnityExtension to see if the Type can be resolved and it returns null if it can’t. This solution was provided by <a href="http://buksbaum.us" target="_blank">David Buksbaum</a> in his blog post <a href="http://buksbaum.us/2009/02/08/type-tracking-extension-for-unity/" target="_blank">Type Tracking Extension for Unity</a>. This extension is added to the container in this wrapper’s constructor.</p>
<p>I did modify David’s extension a little, to have it not overwrite the first registered type and to have CanResolve return true for types that can be initiated also (the original only returns true for types that have been registered). My version looks like this:</p>
<pre class="c-sharp" name="code">
public class TypeTrackingExtension : UnityContainerExtension
{
    private readonly Dictionary&lt;Type, HashSet&lt;string&gt;&gt; registeredTypes = new Dictionary&lt;Type, HashSet&lt;string&gt;&gt;();

    protected override void Initialize()
    {
        Context.Container.Configure&lt;UnityDefaultBehaviorExtension&gt;().Remove();
        Context.Container.Configure&lt;InjectedMembers&gt;().Remove();
        //we have to be the first in the chain
        Context.RegisteringInstance += OnNewInstance;
        Context.Registering += OnNewType;

        Context.Container.Configure&lt;UnityDefaultBehaviorExtension&gt;().InitializeExtension(Context);
        Context.Container.Configure&lt;InjectedMembers&gt;().InitializeExtension(Context);
    }

    public override void Remove()
    {
        base.Remove();
        Context.RegisteringInstance -= OnNewInstance;
        Context.Registering -= OnNewType;
    }
    private void OnNewInstance(object sender, RegisterInstanceEventArgs e)
    {
        HashSet&lt;string&gt; names;
        string name = string.IsNullOrEmpty(e.Name) ? string.Empty : e.Name;

        if (!registeredTypes.TryGetValue(e.RegisteredType, out names))
        { //  not found, so add it
            registeredTypes.Add(e.RegisteredType, new HashSet&lt;string&gt; { name });
        }
        else
        { //  already added type, so add name
            if (name == String.Empty &#038;&#038; names.Contains(name))
            {
                //default instance is already registered, let's give it a name so we can use ResolveAll() like it works in all other ioc containers
                name = e.Name = Guid.NewGuid().ToString();
            }
            names.Add(name);
        }
    }
    private void OnNewType(object sender, RegisterEventArgs e)
    {
        HashSet&lt;string&gt; names;
        string name = string.IsNullOrEmpty(e.Name) ? string.Empty : e.Name;
        if (!registeredTypes.TryGetValue(e.TypeFrom, out names))
        { //  not found, so add it
            registeredTypes.Add(e.TypeFrom, new HashSet&lt;string&gt; { name });
        }
        else
        { //  already added type, so add name
            if (name == String.Empty &#038;&#038; names.Contains(name))
            {
                //default instance is already registered, let's give it a name so we can use ResolveAll() like it works in all other ioc containers
                name = e.Name = Guid.NewGuid().ToString();
            }
            names.Add(name);
        }
    }

    /// &lt;summary&gt;
    /// Determines whether this type can be resolved as the default.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can resolve; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve&lt;T&gt;()
    {
        return CanResolve(typeof(T), null);
    }
    /// &lt;summary&gt;
    /// Determines whether this type can be resolved as the default.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can resolve; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve(Type type)
    {
        return CanResolve(type, null);
    }
    /// &lt;summary&gt;
    /// Determines whether this type can be resolved with the specified name.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved with the specified name; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve&lt;T&gt;(string name)
    {
        return CanResolve(typeof (T), name);
    }

    /// &lt;summary&gt;
    /// Determines whether this type can be resolved with the specified name.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;param name="name"&gt;The name.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved with the specified name; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve(Type type, string name)
    {
        if (isResolvableClass(type))
            return true;

        HashSet&lt;string&gt; names;
        if (registeredTypes.TryGetValue(type, out names))
        {
            return names.Contains(name ?? string.Empty);
        }
        return false;
    }

    private bool isResolvableClass(Type type)
    {
        return type.IsClass &#038;&#038; !type.IsAbstract;
    }
    /// &lt;summary&gt;
    /// Determines whether this instance can be resolved at all.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved at all; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolveAny&lt;T&gt;()
    {
        return CanResolveAny(typeof(T));
    }

    /// &lt;summary&gt;
    /// Determines whether this instance can be resolved at all.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved at all; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolveAny(Type type)
    {
        return isResolvableClass(type) || registeredTypes.ContainsKey(type);
    }

    /// &lt;summary&gt;
    /// Tries to resolve the type, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or &lt;c&gt;null&lt;/c&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;()
    {
        return TryResolve&lt;T&gt;(default(T));
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type with the specified of name, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name associated with the type.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or &lt;c&gt;null&lt;/c&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(string name)
    {
        return TryResolve&lt;T&gt;(name, default(T));
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="defaultValue"&gt;The default value to return if type not found.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or the &lt;see cref="defaultValue"/&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(T defaultValue)
    {
        if (!CanResolve&lt;T&gt;())
            return defaultValue;
        return Container.Resolve&lt;T&gt;();
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type with the specified of name, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name associated with the type.&lt;/param&gt;
    /// &lt;param name="defaultValue"&gt;The default value to return if type not found.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or the &lt;see cref="defaultValue"/&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(string name, T defaultValue)
    {
        if (!CanResolve&lt;T&gt;(name))
            return defaultValue;
        return Container.Resolve&lt;T&gt;(name);
    }
}
</pre>
<p>As you can see, I change the order of the event chain, by removing UnityDefaultBehaviorExtension from the Container, and then add it again later. This allows us to add a name to the type being registered. If a type is registered multiple times without a name given, a name is given in the form of a unique Guid</p>
<p>So now, if you do<br />
  </p>
<pre class="c-sharp" name="code">
Container.Register&lt;IMyInterFace, MyClass1&gt;();
Container.Register&lt;IMyInterFace, MyClass2&gt;();

var wrapper = new UnityDependencyResolver(Container);
var classes = wrapper.ResolveAll&lt;IMyInterFace&gt;()
</pre>
<p>classes will contain both MyClass1 and MyClass2!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=SqSo6RLpLUk:rwlisTyvcsA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/</feedburner:origLink></item>
		<item>
		<title>Fluent NHibernate’s AutoPersistenceModel: I Love it!</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/NJ_l7IiGpgk/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 20:52:04 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/</guid>
		<description><![CDATA[I checked out the latest version of Fluent NHibernate today and noticed the AutoPersistenceModel. I looked at the unit-tests to see what it’s supposed to do and I loved what I saw… Let’s say you have a 2 simple classes like this: Now, in the global.asax’s init (assuming a web application), we can configure NHibernate [...]]]></description>
			<content:encoded><![CDATA[<p>I checked out the latest version of <a href="http://code.google.com/p/fluent-nhibernate/">Fluent NHibernate</a> today and noticed the AutoPersistenceModel. I looked at the unit-tests to see what it’s supposed to do and I loved what I saw…</p>
<p>Let’s say you have a 2 simple classes like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="259" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image.png" width="344" border="0" /> </p>
<p>Now, in the global.asax’s init (assuming a web application), we can configure NHibernate using Fluent NHibernate like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="185" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image1.png" width="577" border="0" /> </p>
<p>It uses convention over configuration in lots of places, eg the Id property is always used as identity-column if a property with that name exists.   <br />But you could also easily add your own conventions. If you want to have the Id colums to be ArtistId and AlbumId (and any other className + Id), you’d do:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="56" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image2.png" width="465" border="0" /> </p>
<p>Want to restrict the namespace as well? No problem!</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="68" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image3.png" width="463" border="0" /> </p>
<p>Fantastic! Now, to see what mapping file this code automagically creates for our Artist class, we can run the following code:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="119" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image4.png" width="300" border="0" /> </p>
<p>which returns an XmlDocument. In this case, the InnerXml of that document looks like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="312" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image5.png" width="552" border="0" /> </p>
<p>Again: fantastic! See how it even generates the one-to-many relation with the correct end-class, because we defined a property IList&lt;Album&gt;!</p>
<p>Running the same code for the Album class gives:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="246" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image6.png" width="520" border="0" /> </p>
<p>If you want to use Fluent NHibernate the ‘old’ way, you can still add ClassMap&lt;Artist&gt; to your assembly. Hence, you can even mix it with the AutoPersistenceModel! If you have a classmap file, it’ll use that for your class, if it isn’t there it’ll automatically create a mapping for you!</p>
<p>I’m sold! This makes using NHibernate a breeze. You can get up and running with your NHibernate project so much faster now.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=NJ_l7IiGpgk:CtRJLfgbeaM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/</feedburner:origLink></item>
		<item>
		<title>jQuery ajax with asp.net mvc preview 5</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/nwfBDwyhtIE/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 18:48:57 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=64</guid>
		<description><![CDATA[Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out scott&#8217;s post to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly [...]]]></description>
			<content:encoded><![CDATA[<p>Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">scott&#8217;s post</a> to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly download the stuff: it&#8217;s at <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">codeplex</a>. </p>
<p>The javascript-only package includes 3 javascript files that allow you to use the default Microsoft AjaxHelper. You can just copy those files to your Content folder and include them in your head section, instead of the MicrosoftAjax.js and MicrosoftMvcAjax.js. All ajax extensions work the same as their Microsoft equivalence,&#160; using jQuery instead of MicrosoftAjax. As a little bonus, you&#8217;ll get back and forward button support for your ajax-links.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="92" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image-thumb.png" width="644" border="0" /></a> </p>
<p>That&#8217;s it, go ahead and use the AjaxHelper functions like you&#8217;re used to. Though a few things have changed for the AjaxHelpers in preview 5, you could still use the introduction <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">ASP.NET MVC Preview 4 &#8211; Using Ajax and Ajax.Form</a> by Scott Hanselman if you haven&#8217;t already checked out the AjaxHelper. Main thing that has changed is that you cannot use inline javascript in the AjaxOptions in preview 5, you should now specify a method name. You could also download the entire jQueryMvc project, it holds a sample website showing some of the ajax magic.</p>
<p>Talking about the entire project, it&#8217;s more than just the .js files! The intention of the project is to get you up and running very quickly when you want to create an mvc based ajax application. We use <a href="http://codeplex.com/unity">Unity</a> as our default IoC container.</p>
<p>I think it&#8217;s quite hard to explain exactly what the project does for you, it&#8217;s best really to just look at the sample website, but I will give a brief overview. First, we have a DefaultViewViewEngine. If you mark your controller with a [DefaultView] attribute like so:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image1.png" width="406" border="0" /> </p>
<p>If you call in example /Home/Index, by default the Index view will be searched for. If it isn&#8217;t found, the DefaultViewViewEngine will look for a template with the name specified (&quot;default&quot; in the above example). It doesn&#8217;t matter what viewengine you use for your views, it will work for all of them. So what can this do? Look at the structure of the views in the sample site:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="261" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image2.png" width="189" border="0" /> </p>
<p>As you can see, most of the the views only have an ascx file prefixed with an underscore. Since the views are not found when the actions Home/About, Home/SayHello, Home/Index are called upon, the DefaultViewViewEngine will open Shared/Default.aspx.    <br />This default page does not do much<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="76" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image3.png" width="879" border="0" /> </p>
<p>As you can see, it just uses the masterpage. But with only little imagination, you can see that you can easily create different default-pages for each controller. The masterpage however, does hold some extra magic:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image4.png" width="506" border="0" /></p>
<p>This special contentplaceholder, by default works like a normal placeholder. But, if it doesn&#8217;t get new content from it&#8217;s page, it will ask the ViewEngine(s) to open the view of the current action prefixed with an underscore. So, if you call Home/About, this will ask for Home/_About.&#160; <br />Can you see the magic? For all similar pages, you just have to create the ascx files (or other partials if you use a different viewengine). Those partial views will be pushed into the main page.</p>
<p>But wait, there&#8217;s more! If you make an ajax-request to a controller that has the [AjaxController] attribute, it will return only the partial view! Now, isn&#8217;t that great ? That looks a lot like the updatepanel to me <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">Go to codeplex and download the project to see the ajax-magic I&#8217;m so excited about!</a>    <br />Source can be downloaded at Google code: <a href="http://code.google.com/p/jquerymvc/source/checkout">http://code.google.com/p/jquerymvc/source/checkout</a>    <br />The sample website can be seen in action at: <a title="http://www.chrisvandesteeg.nl/demo/jquerymvc5/" href="http://www.chrisvandesteeg.nl/demo/jquerymvc5/">http://www.chrisvandesteeg.nl/demo/jquerymvc5/</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=nwfBDwyhtIE:JzkeUEij9XQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/</feedburner:origLink></item>
		<item>
		<title>Howto use jQuery with asp.net mvc preview 4′s AjaxHelper</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/UnbV8FRLrXU/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 20:56:11 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</guid>
		<description><![CDATA[Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper. Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that [...]]]></description>
			<content:encoded><![CDATA[<p>Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper.</p>
<p>Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that uses the same methodnames as the MicrosoftMvcAjax version.</p>
<p>Though at first I was upset that AjaxHelper wasn&#8217;t opened up, this javascript-only solution makes it very easy to use. All you have to do is </p>
<ul>
<li>place the <a href="http://jquery.com/">latest jQuery version</a> in your Content folder; </li>
<li>place <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">my javascript file</a> in your Content folder; </li>
<li>add references in your views (or masterpage ofcourse) to these 2 files instead of referencing the MicrosoftMvcAjax.js and MicrosoftAjax.js file.</li>
</ul>
<p>If you haven&#8217;t played with the AjaxHelper yet, take a look at <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">Scott Hanselman&#8217;s post on Using Ajax and Ajax.Form</a></p>
<p>This jQuery version also has a little extra: browser-history support for your ajax requests</p>
<p>Now, go <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">download</a> the js file and play!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=UnbV8FRLrXU:spZ08lkylEM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</feedburner:origLink></item>
		<item>
		<title>jQuery for Asp.net MVC preview 3</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/8QF1wRT2cIQ/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/06/13/jquery-for-aspnet-mvc-preview-3/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 13:13:08 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/06/13/jquery-for-aspnet-mvc-preview-3/</guid>
		<description><![CDATA[So, I finally got a chance to sit down and finish up the jQuery for Asp.net Mvc preview 3. If you haven&#8217;t already read Scott&#8217;s post about preview 3,&#160; you should definitely do so before reading this one. So, quite some things have changed in preview 3, which made me decide to change a lot [...]]]></description>
			<content:encoded><![CDATA[<p>So, I finally got a chance to sit down and finish up the jQuery for Asp.net Mvc preview 3. If you haven&#8217;t already read <a href="http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx">Scott&#8217;s post about preview 3</a>,&#160; you should definitely do so before reading this one.</p>
<p>So, quite some things have changed in preview 3, which made me decide to change a lot in the jQuery for Asp.net mvc (<em>jqmvc</em>) too. To start with most radical one: I ditched the ajax.master. This little &#8216;framework&#8217; does not rely on a special masterpage in your website from now on. Since things have radically changed, I&#8217;ll start all over again on how to use this project. </p>
<p>In this post, I&#8217;ll explain how the project works globally. I won&#8217;t go into too much details about everything, but I will just explain the things you&#8217;ll directly touch in your application. In the next post, I&#8217;ll explain how to <em>use</em> the project in your website (until that time you could take a look at the included sample website). That post will explain the Ajax- and HtmlHelpers in this project and it will explain how to do an ajax request using jQuery.</p>
<p>Before my story starts, let&#8217;s start with the links and downloads for all those who want to read code rather than stories :</p>
<ul>
<li><a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=14383">Downloads</a>&#160;</li>
<li><a href="http://code.google.com/p/jquerymvc/source/checkout">SVN source Repository</a></li>
<li><a href="http://code.google.com/p/jquerymvc/downloads/detail?name=preview%203%20bin.zip&amp;can=2&amp;q="></a><a href="http://www.chrisvandesteeg.nl/demo/jquerymvc3/default.aspx">The online demo</a> </li>
<li><a href="http://www.codeplex.com/jquery4mvc/">Codeplex homepage</a></li>
</ul>
<h2>Application and routes</h2>
<p>To have a quick go for your application, it&#8217;s recommended that you inherit your application from JqueryMvc.JqueryMvcApplication. You can ofcourse easily do this in your global.asax like so:    <br /><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="22" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/06/image3.png" width="531" border="0" />     <br />This application sets up the Unity dependency container and will set up the default routes. If you wish to setup a different (or no) dependency container, you should override InitializeContainer() and ConfigureContainer(). JQueryMvc itself is no longer dependent on a dependency container.</p>
<p>I found it hard to set up the default routes in preview 3 if your server does not support wildcard redirects (like visual studio&#8217;s webdevserver doesn&#8217;t). In that case you need to catch existing files (default.aspx needs to exist, but shouldn&#8217;t do anything), but you need to skip the Content folder. I came up with the following solution:    <br /><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="648" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/06/image6.png" width="536" border="0" />     <br />So if there&#8217;s a default.aspx in the root of your application, it set&#8217;s routeExistingFiles to true. If the url matches the RegEx ^Content\/.* the routing will be stopped using the new IgnoreRoute method. Also, your controllers will then be extended with .aspx to be sure the requests passes the asp.net cycle. If you have the option to catch all incoming requests, all you have to do is remove the default.aspx from the root of your website.</p>
<h1></h1>
<h2>Controllers</h2>
<p>As you&#8217;ve seen in Scott&#8217;s post, controllers should now return an ActionResult. The normal way would be to have your controller action return the result of the View() method. With <em>jqmvc</em> you should not call the View() method at the end of your action. Ofcourse, if you&#8217;re sure you want to return the normal view, you could still do so. In <em>jqmvc</em> there is a ExtController which you should inherit your controllers from. This baseclass contains a method called Action() which accepts the same attributes as View() but does some magic to decide what type of request the current request is, and will try to return the correct ActionResult for that type of request. This could be either an Ajax-request, a Json request or a normal page-request. Your typical controller with some actions would look like this:</p>
<p>&#160;&#160; <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="399" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/06/image7.png" width="537" border="0" /></p>
<h2>Views</h2>
<p>If <em>jqmvc</em> encountered the current request as a normal page request, it will create the default ViewResult, nothing special there.</p>
<p>If <em>jqmvc </em>decided Json should be returned, a JsonResult is created and no further actions will be taken. The rendered view will be the ViewData serialized to Json. The ViewEngine of the controller is also changed to a JsonViewEngine but this is only called upon in case of an Exception.</p>
<p>If <em>jqmvc</em> decided that the request is an Ajax request, it will create a normal ViewResult, but it will change the ViewLocator of the controller.     <br />(Offtopic: I think it&#8217;s a design-error to have the viewlocator on the controller. It should be on the ViewResult object, that&#8217;s the only object that uses it. Perhaps this will be changed in the next preview&#8230;)     <br />This AjaxViewLocator will first look for .ascx files instead of .aspx files. If it can&#8217;t find the .ascx it will load .aspx afterall.&#160; You can also create a target-specific .ascx file: if you do an ajax-request through our javascript function jQuery.mvc.request() (or one of the htmlhelper functions), you have to specify a target for the loaded content. Let&#8217;s say we want to load /Home/Index into a &lt;div id=&quot;dynamiccontent&quot;&gt;&lt;/div&gt;     <br />The AjaxViewLocator will then look for :</p>
<ol>
<li>/Views/Home/Index.dynamiccontent.ascx </li>
<li>/Views/Home/Index.acx </li>
<li>/Views/Home/dynamiccontent.ascx </li>
<li>/Views/Home/Index.aspx </li>
<li>/Views/Shared/Index.dynamiccontent.ascx </li>
<li>/Views/Shared/Index.ascx </li>
<li>/Views/Shared/dynamiccontent.ascx </li>
<li>/Views/Shared/Index.aspx </li>
</ol>
<p>To have the page /Home/index available both as an ajax request as well as normal request, you could create an /Views/Home/Index.aspx which loads the index.ascx like so:<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="25" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/06/image1.png" width="454" border="0" /> </p>
<h2>Things to know</h2>
<h4></h4>
<ul>
<li>
<p>We have some HelperClasses to simplify the use of <em>jqmvc</em></p>
</li>
<li>
<p>The ViewData keys &quot;Messages&quot; and &quot;Errors&quot; are treated specially by <em>jqmvc.</em> </p>
</li>
<li>
<p>Your page should always contain:</p>
<ul>
<li>
<p>&lt;%= Html.RegisterJqueryMvc(Page.ClientScript) %&gt; To register the required javascript files</p>
</li>
<li>
<p>&lt;div id=&quot;loading&quot;&gt;&lt;/div&gt;; or something else with id=&quot;loading&quot;. This will be made visible during ajax-requests</p>
</li>
<li>
<p>&lt;div id=&quot;errors&quot;&gt;&lt;/div&gt; to display errors</p>
</li>
<li>
<p>&lt;div id=&quot;messages&quot;&gt;&lt;/div&gt; to display messages (informational)</p>
</li>
</ul>
</li>
<li>
<p>We have a special contentplaceholder in JqueryMvc.UI.WebControls.ContentPlaceHolder. This will use the AjaxViewLocator to load some default content. Eg, if used like this in your masterpage, and the current request is /Home/Index:        <br />&lt;jq:ContentPlaceHolder ID=&quot;maincontent&quot; runat=&quot;server&quot; /&gt;         <br />It will look for for content in:</p>
<ol>       </ol>
<ol>
<li>/Views/Home/Index.maincontent.ascx </li>
<li>/Views/Home/Index.acx </li>
<li>/Views/Home/maincontent.ascx </li>
<li>/Views/Home/Index.aspx </li>
<li>/Views/Shared/Index.maincontent.ascx </li>
<li>/Views/Shared/Index.ascx </li>
<li>/Views/Shared/maincontent.ascx </li>
<li>/Views/Shared/Index.aspx
<p>This way, your index.aspx could just be an empty page that points to MasterPage with this default-content-loading contentplaceholer.<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/06/image2.png" width="454" border="0" /> </li>
</ol>
</li>
<li>Your ascx files should inherit from JqueryMvc.Mvc.ExtViewUserControl to have access to the AjaxHelper (bug in asp.net mvc!) and to have the messages &amp; errors parsed by <em>jqmvc</em>. </li>
<li>In case of an error the default controller will look for a rescue page in /Views/[ControllerName]/Rescues/error.aspx or /Views/Shared/Rescues/error.aspx (or .ascx in case of an ajax request). You can specify your own rescues for different types of errors by using the RescueAttribute of </li>
<li>You should remove default.aspx if your application-server supports wildcard mappings. </li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=8QF1wRT2cIQ:uPABw-E8NlI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/06/13/jquery-for-aspnet-mvc-preview-3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/06/13/jquery-for-aspnet-mvc-preview-3/</feedburner:origLink></item>
		<item>
		<title>jQuery for ASP.NET MVC preview 2</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/BrvUBIwlgqU/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/03/26/jquery-for-aspnet-mvc-preview-2/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 19:37:22 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/03/26/jquery-for-aspnet-mvc-preview-2/</guid>
		<description><![CDATA[I updated the jQueryMvc project so that it works with ASP.NET MVC preview 2. I also switched the IoC container from Objectbuilder to Unity. I submitted the Unity container to the MvcContrib project but it has not yet been accepted in their repository, so you&#8217;ll have to do with the unofficial version I include in [...]]]></description>
			<content:encoded><![CDATA[<p>I updated the jQueryMvc project so that it works with <a href="http://www.google.nl/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3FFamilyID%3D38cc4cf1-773a-47e1-8125-ba3369bf54a3&amp;ei=t57qR77FIJacxAHfgu31Cg&amp;usg=AFQjCNH5Y3w0Qt8KMrr3vLRHHQH1GwEJpQ&amp;sig2=_BtORUlMGY88ZK2Qqjz46g">ASP.NET MVC preview 2</a>. I also switched the IoC container from Objectbuilder to <a href="http://www.codeplex.com/unity">Unity</a>. I submitted the Unity container to the <a href="http://www.mvccontrib.org">MvcContrib</a> project but it has not yet been accepted in their repository, so you&#8217;ll have to do with the unofficial version I include in the download. Unity is, to put it very baldly, Objectbuilder version 2. So it seemed logical to make the switch.</p>
<p>I also made up a nice(r) way to inject the ViewEngine into the BaseController. It&#8217;s now injected through a public method using a MethodInjection attribute:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="137" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/03/image.png" width="450" border="0"/></p>
<p>Thanks to this method, we no longer have pre-register all the Controllers with our container (in the previous version of jQueryMvc I scanned all dll&#8217;s on ApplicationStart to register the Controller and assign the ServiceViewFactory as the default ViewFactory)</p>
<p>Furthermore, since the ASP.NET MVC team decided to change the way the Views are rendered (now through a ViewEngine, which is nice I think), it was no longer needed to use the code from <a href="http://www.aaronlerch.com/blog/2008/01/01/unifying-web-sites-and-web-services-with-the-aspnet-mvc-framework/">Aaron Lerch</a>. Though still inspired by his code ofcourse, I removed almost all of his code now. We now have a single &#8216;<a href="http://jquerymvc.googlecode.com/svn/trunk/jQueryMvc/ServiceViewEngine.cs">ServiceViewEngine</a>&#8216; inheriting from the ASP.NET MVC&#8217;s default WebFormViewEngine. All code deciding what view to render, is now located in this class.</p>
<p>What I did not like about preview 2, is that the name of the master-template cannot be set from within the ViewEngine. It&#8217;s now stored into the ViewContext, and the setter is private <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . So now the mastertemplate is set in the BaseController, causing the BaseController to have to know what type of request the current one is (which is bad):</p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="191" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/03/image1.png" width="577" border="0"/> </p>
<p>As usual, you can download the hottest source from the Subversion repository at <a title="http://code.google.com/p/jquerymvc/source/checkout" href="http://code.google.com/p/jquerymvc/source/checkout">http://code.google.com/p/jquerymvc/source/checkout</a> or you can <a href="/download/jquerymvc/jquerymvc-0.3.zip">download a zipped package of the source code</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=BrvUBIwlgqU:yRhhH8TDKXU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/03/26/jquery-for-aspnet-mvc-preview-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/03/26/jquery-for-aspnet-mvc-preview-2/</feedburner:origLink></item>
	</channel>
</rss>

