<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Glavs Blog</title><link>http://weblogs.asp.net/pglavich/default.aspx</link><description>The dotDude of .Net</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>ScriptHelper now a Nuget package, and managing your Javascript</title><link>http://weblogs.asp.net/pglavich/archive/2012/01/21/scripthelper-now-a-nuget-package-and-managing-your-javascript.aspx</link><pubDate>Sat, 21 Jan 2012 03:45:54 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8265584</guid><dc:creator>Glav</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=8265584</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2012/01/21/scripthelper-now-a-nuget-package-and-managing-your-javascript.aspx#comments</comments><description>&lt;p&gt;For a while now I have been looking at different ways of managing javascript inclusion in web pages, and also managing the dependencies that each script inclusion requires. Furthermore, working with ASP.NET MVC and partial views, working with the ever increasing number of dependencies as well as ensuring that each partial view has the script it requires, can be a little challenging. At the very least messy and tedious.&lt;/p&gt;  &lt;p&gt;Ideally, I’d like every page or partial view to be able to express what scripts it requires and let the framework care about removing duplication, minification etc.&lt;/p&gt;  &lt;p&gt;So, after looking at the needs of our application, as well as the needs of others I developed the ScriptHelper component which is now available as a &lt;a href="http://nuget.org/packages/ScriptHelper" target="_blank"&gt;Nuget package&lt;/a&gt;. I had released an initial version some time ago, details are &lt;a href="http://weblogs.asp.net/pglavich/archive/2010/11/18/scripthelper-for-mvc-and-webforms-projects.aspx" target="_blank"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;This latest version has the following features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Support for &lt;font face="Courier New"&gt;RequiresScriptsDeferred&lt;/font&gt; and &lt;font face="Courier New"&gt;RenderDeferred&lt;/font&gt; methods to allow you to specify script requirements as many times as you like, where ever you like and to have these requirements only rendered to the page when the &lt;font face="Courier New"&gt;RenderDeferred&lt;/font&gt; method is called. This makes it easy to include the &lt;font face="Courier New"&gt;RenderDeferred&lt;/font&gt; at the bottom of your master page so all deferred scripts are rendered then. These scripts can be minified and combined at this time as well. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So you can do:&lt;/p&gt;  &lt;pre&gt;&lt;font size="2" face="Arial Narrow"&gt;@ScriptDependencyExtension.ScriptHelper.&lt;strong&gt;RequiresScriptsDeferred&lt;/strong&gt;(&amp;quot;jQuery&amp;quot;)&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;and maybe somewhere else in the page or in another partial view&lt;/p&gt;

&lt;pre&gt;&lt;font size="2" face="Arial Narrow"&gt;@ScriptDependencyExtension.ScriptHelper.&lt;strong&gt;RequiresScriptsDeferred&lt;/strong&gt;(&amp;quot;jQuery-validate-unobtrusive&amp;quot;)&lt;/font&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;font size="1"&gt;&lt;font size="2" face="Arial Narrow"&gt;@ScriptDependencyExtension.ScriptHelper.&lt;strong&gt;RequiresScriptsDeferred&lt;/strong&gt;(&amp;quot;SomeOtherScripts&amp;quot;)&lt;/font&gt; &lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Then when the:&lt;/p&gt;

&lt;pre&gt;&lt;font size="2" face="Arial Narrow"&gt;@ScriptDependencyExtension.ScriptHelper.&lt;strong&gt;RenderDeferredScripts&lt;/strong&gt;()&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;is called, all the previously deferred scripts are combined, minified and rendered as one single file inclusion&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Support for &lt;a href="http://www.dotlesscss.org/" target="_blank"&gt;.Less&lt;/a&gt; so you can have variables and functions in your CSS. No need to use a .less extension as .&lt;a href="http://www.dotlesscss.org/" target="_blank"&gt;Less&lt;/a&gt; is automatically invoked if it is enabled for the first time it is required. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: Although the project source is titled as an MVC script helper, it can also be used within Webforms without issue as it is a simple static method with no reliance on anything from MVC. I just happened to start coding it with an MVC project in mind.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Additionally, the helper fully supports CSS and .less CSS semantics and syntax.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are other frameworks that do similar things but I created this one for a few reasons:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The code is pretty small and simple. Very easy to modify and extend to suit your own purposes. It currently uses the Microsoft Ajax minifier. If you dont like it, implement the “&lt;font face="Courier New"&gt;IScriptProcessingFilter&lt;/font&gt;” and replace the current minifier component with your own. &lt;/li&gt;

  &lt;li&gt;I liked the ability to express dependencies explicitly. The number of JS libraries to use grows every day and it can get tricky in large apps to easily see what is required and needed. &lt;/li&gt;

  &lt;li&gt;I didn’t find one that &lt;em&gt;easily&lt;/em&gt; implemented the deferred loading scenario, took care of duplicates, and minification, and .less support. Maybe there is now, but I got started on it anyway. Or maybe there is one, but the implementation looked ugly. Either way, I wasn’t satisfied with the current offerings. &lt;/li&gt;

  &lt;li&gt;I like coding stuff &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/pglavich/wlEmoticon-smile_3A6E8B78.png" /&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Download the Nuget package from &lt;a href="http://nuget.org/packages/ScriptHelper" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Download the source from &lt;a href="https://bitbucket.org/glav/mvc-script-dependency-extension" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For full documentation on ScriptHelper (minus the new features here), see &lt;a href="http://weblogs.asp.net/pglavich/archive/2010/11/18/scripthelper-for-mvc-and-webforms-projects.aspx" target="_blank"&gt;this post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;font face="Courier New"&gt;ReadMe.txt&lt;/font&gt; file is included in the package with all configuration details.&lt;/p&gt;

&lt;h4&gt;But .Net 4.5 will include a bundling facility to address some this. Why would I use this?&lt;/h4&gt;

&lt;p&gt;See &lt;a href="http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx" target="_blank"&gt;Scott Gu’s blog post&lt;/a&gt; for more info on this feature.&lt;/p&gt;

&lt;p&gt;Well of course you don't have to and if you were happy with the default way bundling works, it is probably worth sticking with that. I mean, you don’t want to include extra libraries if you don’t have to.&lt;/p&gt;

&lt;p&gt;However the bundling supports expressing dependencies programmatically in code. it is ok, but I prefer the XML file. Easier to read and define IMO. Sure the code isn’t that hard to read, but it could be anywhere and takes a bit more analysis to see all of the dependencies any one component may need.&lt;/p&gt;

&lt;p&gt;There is no support for .less files out of the box. I am sure this wont be far off as adding .less support is pretty trivial. However it is not in there by default.&lt;/p&gt;

&lt;p&gt;Bundling will include what you tell it to when you tell it to. This is good, but I love the idea of views or pages being able to express their dependencies without worry of script duplication. The deferred script loading feature of the ScriptHelper was one of my main reasons for developing this. If you don’t use deferred script loading/inclusion, then ScriptHelper will assume you know what you are doing and include the script file immediately as per bundling.&lt;/p&gt;

&lt;p&gt;The bundling feature will use .Net 4.5. If you are bound to lower versions of the framework, this is a blocker. ScriptHelper is compiled against .Net 4, however there is nothing that really relies on .Net 4 specifics. If you were targeting .Net 1, it could prove a little tricky as generics are used and a few other features, but migrating/compiling against lower versions should not be very hard.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Managing your Javascript&lt;/h2&gt;

&lt;p&gt;So how does this help manage your javascript in your projects?&lt;/p&gt;

&lt;h3&gt;PartialViews&lt;/h3&gt;

&lt;p&gt;Normally partial views, other pages either rely on a knowledge of what is included via the master page and what is also included on the content page itself in terms of scripts. A partial view may include its own scripts, provided that script is not included elsewhere to prevent duplicate script files being loaded.&lt;/p&gt;

&lt;p&gt;Using ScriptHelper and DeferredScripts your partial view can include anything all its dependencies. So the partial view can use the “&lt;font face="Courier New"&gt;RequiresScriptsDeferred&lt;/font&gt;” method to express its dependencies. At some point in time, typically at the bottom of your master page/layout, you will call the “&lt;font face="Courier New"&gt;RenderDeferredScripts&lt;/font&gt;” where all the required scripts are rendered. Typically this is also used with script combination and minification so that only 1 include is rendered. All duplicate inclusions are ignored, all files are combined, minified, and .less filter is run over it if required. A single script include is generated and your done. If the master page/layout has already expressed dependencies (such as jQuery for example) and the partial view also expresses this dependencies, it is ignored.&lt;/p&gt;

&lt;p&gt;This means each partial view, component or page can express all its dependencies that it requires without fear of duplication.&lt;/p&gt;

&lt;h3&gt;Script Dependencies&lt;/h3&gt;

&lt;p&gt;The way ScriptHelper works is by using a friendly name to group one or more script files together in the &lt;font face="Courier New"&gt;ScriptDependencies.xml&lt;/font&gt; file. The way this is all grouped is up to you. You can group by component (jQuery, validation, etc…) or even by page or anything else. There only needs to be 1 reference to the explicit name of your script, everything else is by friendly name so when a version number of a script changes, potentially changing the name of the script file, you only need to change the name of the file in one place.&lt;/p&gt;

&lt;p&gt;In addition, the dependencies for scripts in the XML file are listed explicitly. There is no guesswork as to what script require what in terms of dependencies since it is listed for easy identification.&lt;/p&gt;

&lt;p&gt;Finally, if you like having version identifiers on your query strings to assist with browser caching, this can also be expressed in the &lt;font face="Courier New"&gt;ScriptDependencies.xml&lt;/font&gt; file. This means you can have a script with &lt;a href="http://host/script.js?v=123"&gt;&lt;font face="Courier New"&gt;http://host/script.js?v=123&lt;/font&gt;&lt;/a&gt; where the &lt;font face="Courier New"&gt;v=123&lt;/font&gt; is the version identifier. The ‘&lt;font face="Courier New"&gt;v&lt;/font&gt;’ and the ‘&lt;font face="Courier New"&gt;123&lt;/font&gt;’ are all declared in the XML file which is easily updated manually or via a build script.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So if you find yourself in Javascript inclusion and dependency hell, give this library a shot, it may help.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8265584" width="1" height="1"&gt;</description></item><item><title>My Code Kata–A Solution Kata</title><link>http://weblogs.asp.net/pglavich/archive/2011/11/13/my-code-kata-a-solution-kata.aspx</link><pubDate>Sun, 13 Nov 2011 03:53:56 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8051632</guid><dc:creator>Glav</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=8051632</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/11/13/my-code-kata-a-solution-kata.aspx#comments</comments><description>&lt;p&gt;There are many developers and coders out there who like to do &lt;a href="http://codekata.pragprog.com/2007/01/code_kata_backg.html" target="_blank"&gt;code Kata’s&lt;/a&gt; to keep their coding ability up to scratch and to practice their skills. I think it is a good idea.&lt;/p&gt;  &lt;p&gt;While I like the concept, I find them dead boring and of minimal purpose. Yes, they serve to hone your skills but that’s about it. They are often quite abstract, in that they usually focus on a small problem set requiring specific solutions. It is fair enough as that is how they are designed but again, I find them quite boring.&lt;/p&gt;  &lt;p&gt;What I personally like to do is go for something a little larger and a little more fun. It takes a little more time and is not as easily executed as a kata though, but it services the same purposes from a practice perspective and allows me to continue to solve some problems that are not directly part of the initial goal. This means I can cover a broader learning range and have a bit more fun. If I am lucky, sometimes they even end up being useful tools.&lt;/p&gt;  &lt;p&gt;With that in mind, I thought I’d share my current ‘kata’. It is not really a code kata as it is too big. I prefer to think of it as a ‘solution kata’.&lt;/p&gt;  &lt;p&gt;The code is on bitbucket &lt;a href="https://bitbucket.org/glav/ecodev/overview" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;What I wanted to do was create a kind of simplistic virtual world where I can create a player, or a class, stuff it into the world, and see if it survives, and can navigate its way to the exit.&lt;/p&gt;  &lt;p&gt;Requirements were pretty simple:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Must be able to define a map to describe the world using simple X,Y co-ordinates. Z co-ordinates as well if you feel like getting clever. &lt;/li&gt;    &lt;li&gt;Should have the concept of entrances, exists, solid blocks, and potentially other materials (again if you want to get clever). &lt;/li&gt;    &lt;li&gt;A coder should be able to easily write a class which will act as an inhabitant of the world. &lt;/li&gt;    &lt;li&gt;An inhabitant will receive stimulus from the world in the form of surrounding environment and be able to make a decision on action which it passes back to the ‘world’ for processing. &lt;/li&gt;    &lt;li&gt;At a minimum, an inhabitant will have sight and speed characteristics which determine how far they can ‘see’ in the world, and how fast they can move. &lt;/li&gt;    &lt;li&gt;Coders who write a really bad ‘inhabitant’ should not adversely affect the rest of world. &lt;/li&gt;    &lt;li&gt;Should allow multiple inhabitants in the world. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;So that was the solution I set out to act as a practice solution and a little bit of fun. It had some interesting problems to solve and I figured, if it turned out ok, I could potentially use this as a ‘developer test’ for interviews. Ask a potential coder to write a class for an inhabitant. Show the coder the map they will navigate, but also mention that we will use their code to navigate a map they have not yet seen and a little more complex.&lt;/p&gt;  &lt;p&gt;I have been playing with solution for a short time now and have it working in basic concepts. Below is a screen shot using a very basic console visualiser that shows the map, boundaries, blocks, entrance, exit and players/inhabitants.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/image_66E77FBC.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/pglavich/image_thumb_4925F4FD.png" width="170" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The yellow asterisks ‘&lt;font style="background-color: #a5a5a5" color="#ffff00"&gt;*&lt;/font&gt;’ are the players, green ‘&lt;font style="background-color: #a5a5a5" color="#00ff00"&gt;O&lt;/font&gt;’ the entrance, purple ‘&lt;font style="background-color: #666666" color="#9b00d3"&gt;^&lt;/font&gt;’ the exit, maroon/browny ‘&lt;font style="background-color: #a5a5a5" color="#c0504d"&gt;#&lt;/font&gt;’ are solid blocks.&lt;/p&gt;  &lt;p&gt;The players can move around at different speeds, knock into each others, and make directional movement decisions based on what they see and who is around them. It has been quite fun to write and it is also quite fun to develop different players to inject into the world.&lt;/p&gt;  &lt;p&gt;The code below shows a really simple implementation of an inhabitant that can work out what to do based on stimulus from the world. It is pretty simple and just tries to move in some direction if there is nothing blocking the path.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:758e0496-1b0f-4bb2-84ee-2cdb6cd81cdb" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestPlayer:LivingEntity
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestPlayer()
    {
        Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Beta Boy&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
        LifeKey &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; Guid.NewGuid();
    }
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;override&lt;/span&gt;&lt;span style="color: #000000;"&gt; ActionResult DecideActionToPerform(EcoDev.Core.Common.Actions.ActionContext actionContext)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;try&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        {
            var action &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; MovementAction();

            &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; move forward if we can&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (actionContext.Position.ForwardFacingPositions.Length &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (CheckAccessibilityOfMapBlock(actionContext.Position.ForwardFacingPositions[&lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;]))
                {
                    action.DirectionToMove &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; MovementDirection.Forward;
                    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; action;
                }
            }
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (actionContext.Position.LeftFacingPositions.Length &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (CheckAccessibilityOfMapBlock(actionContext.Position.LeftFacingPositions[&lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;]))
                {
                    action.DirectionToMove &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; MovementDirection.Left;
                    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; action;
                }
            }
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (actionContext.Position.RearFacingPositions.Length &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (CheckAccessibilityOfMapBlock(actionContext.Position.RearFacingPositions[&lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;]))
                {
                    action.DirectionToMove &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; MovementDirection.Back;
                    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; action;
                }
            }
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (actionContext.Position.RightFacingPositions.Length &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (CheckAccessibilityOfMapBlock(actionContext.Position.RightFacingPositions[&lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;]))
                {
                    action.DirectionToMove &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; MovementDirection.Right;
                    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; action;
                }
            }

            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; action;
        }
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;catch&lt;/span&gt;&lt;span style="color: #000000;"&gt; (Exception ex)
        {
            World.WriteDebugInformation(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Player: &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;+&lt;/span&gt;&lt;span style="color: #000000;"&gt; Name, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;.Format(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Player Generated exception: {0}&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;,ex.Message));
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt;&lt;span style="color: #000000;"&gt; ex;
        }
    }

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; CheckAccessibilityOfMapBlock(MapBlock block)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (block &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;null&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;||&lt;/span&gt;&lt;span style="color: #000000;"&gt; block.Accessibility &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; MapBlockAccessibility.AllowEntry &lt;/span&gt;&lt;span style="color: #000000;"&gt;||&lt;/span&gt;&lt;span style="color: #000000;"&gt; block.Accessibility &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; MapBlockAccessibility.AllowExit &lt;/span&gt;&lt;span style="color: #000000;"&gt;||&lt;/span&gt;&lt;span style="color: #000000;"&gt; block.Accessibility &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; MapBlockAccessibility.AllowPotentialEntry)
        {
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
        }
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    }

}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;It is simple and it seems to work well. The world implementation itself decides the stimulus context that is passed to he inhabitant to make an action decision. All movement is carried out on separate threads and timed appropriately to be as fair as possible and to cater for additional skills such as speed, and eventually maybe stamina, strength, with actions like fighting. It is pretty fun to make up random maps and see how your inhabitant does.&lt;/p&gt;

&lt;p&gt;You can download the code from &lt;a href="https://bitbucket.org/glav/ecodev/overview" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Along the way I have played with parallel extensions to make the compute intensive stuff spread across all cores, had to heavily factor in visibility of methods and properties so design of classes was paramount, work out movement algorithms that play fairly in the world and properly favour the players with higher abilities, as well as a host of other issues.&lt;/p&gt;

&lt;p&gt;So that is my ‘&lt;strong&gt;&lt;em&gt;solution kata&lt;/em&gt;&lt;/strong&gt;’. &lt;/p&gt;

&lt;p&gt;If I keep going with it, I may develop a web interface for it where people can upload assemblies and watch their player within a web browser visualiser and maybe even a map designer. &lt;/p&gt;

&lt;p&gt;What do you do to keep the fires burning?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8051632" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Personal/default.aspx">Personal</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/General/default.aspx">General</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Architecture/default.aspx">Architecture</category></item><item><title>Updates to the CacheAdapter Package</title><link>http://weblogs.asp.net/pglavich/archive/2011/08/21/updates-to-the-cacheadapter-package.aspx</link><pubDate>Sun, 21 Aug 2011 03:12:52 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7919105</guid><dc:creator>Glav</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7919105</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/08/21/updates-to-the-cacheadapter-package.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Note: This post was originally going to detail the changes from 2.0 to 2.1, however in between the time of release and this post, I released 2.2 so this post will detail all the changes up to 2.2.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In the last update to my &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;CacheAdapter&lt;/a&gt; library (you can view it &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/07/04/cacheadapter-v2-now-with-memcached-support.aspx" target="_blank"&gt;here&lt;/a&gt;), I mentioned the support for &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; cache engine. That brought the version to 2.0.&lt;/p&gt;  &lt;p&gt;As previously mentioned, you can get this package from &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I have recently updated the version of the library to &lt;strike&gt;2.1&lt;/strike&gt; 2.2 which now includes the following changes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The ability provide specific configuration data to a particular cache engine without introducing a bunch of specific configuration tags that are only relevant to a particular cache mechanism.      &lt;ul&gt;       &lt;li&gt;Addition of a &lt;font face="Courier New"&gt;CacheSpecificData&lt;/font&gt; configuration element. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;The addition of 2 new simpler API methods to get data from the cache.      &lt;ul&gt;       &lt;li&gt;&lt;font face="Courier New"&gt;T Get&amp;lt;T&amp;gt;(DateTime absoluteExpiryDate, Func&amp;lt;T&amp;gt; getData)&lt;/font&gt; &lt;/li&gt;        &lt;li&gt;&lt;font face="Courier New"&gt;T Get&amp;lt;T&amp;gt;(TimeSpan slidingExpiryWindow, Func&amp;lt;T&amp;gt; getData)&lt;/font&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font face="Arial"&gt;Notice that there is &lt;strong&gt;no&lt;/strong&gt; cache key required to be specified. It is auto generated from the&lt;/font&gt; Func&amp;lt;T&amp;gt; &lt;/font&gt;&lt;font face="Arial"&gt;delegate. (Thanks to &lt;a href="http://www.linkedin.com/in/corneliutusnea" target="_blank"&gt;Corneliu&lt;/a&gt; for this great idea). So you can write really simple code to get data from the cache like so:&lt;/font&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ce63feaf-61f8-4331-9151-f3b6b5d75b4c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;var myData &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheProvider.Get&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;SomeData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(DateTime.Now.AddSeconds(&lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;), () &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                                                                          {
                                                                             var somedata &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; SomeData();
                                                                             &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; populate data from somewhere (db, code etc..)&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;                                                                             &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; somedata;
                                                                          });
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Simplification of the interface 
    &lt;ul&gt;
      &lt;li&gt;Replacing the &lt;font face="Courier New"&gt;GetDataToCacheDelegate&amp;lt;T&amp;gt;()&lt;/font&gt; delegate with a &lt;font face="Courier New"&gt;Func&amp;lt;T&amp;gt;&lt;/font&gt; &lt;/li&gt;

      &lt;li&gt;Removal of the &lt;font face="Courier New"&gt;bool addToPerRequestCache = false&lt;/font&gt; parameter from the &lt;font face="Courier New"&gt;Get&amp;lt;T&amp;gt;&lt;/font&gt; methods. &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So why the new configuration element? Well, previous versions of this library supported Windows Azure AppFabric however it was only in a non Azure scenario. When Windows AppFabric is used within Azure, a security mode and authentication key is required. This is easily achieved with config, but I wanted a way that did not introduce redundant elements that were not applicable to other cache mechanisms AND that may be useful for other cache mechanisms if they require it. Basically, a generic way of providing configuration data to cache mechanisms, that could be used by any cache mechanism and not pollute the configuration with lots of items specific to only 1 method.&lt;/p&gt;

&lt;p&gt;To that end, this release has introduced a “&lt;font face="Courier New"&gt;CacheSpecificData&lt;/font&gt;” configuration element as shown below:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:dc2db394-09c3-4ca8-9311-6b94d2ebc7d7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:White;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;setting &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="CacheSpecificData"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="String"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;value&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;UseSsl=false;SecurityMode=Message;MessageSecurityAuthorizationInfo=your_secure_key_from_azure_dashboard&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;value&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;setting&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Currently, this element is only of use to AppFabric cache mechanism, but as support for more cache types grow, this item will be used more and more.&lt;/p&gt;

&lt;p&gt;This element is a simple series of key/value pairs that are separated by a semi-colon. In the example above, the following values are defined:&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;UseSsl = &lt;strong&gt;false&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;SecurityMode = &lt;strong&gt;Message&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;MessageSecurityAuthorizationInfo = &lt;strong&gt;your_secure_key_from_azure_dashboard&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;This equates to the following configuration for Windows AppFabric in Azure (Specifically the &lt;font face="Courier New"&gt;&amp;lt;SecurityProperties&amp;gt;&lt;/font&gt; element):&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:4500570c-5dca-4e43-bb97-c731c92ef5d7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:White;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;dataCacheClients&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;dataCacheClient &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="default"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;hosts&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;host &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="somehost.com"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; cachePort&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="22233"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;hosts&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;securityProperties &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;mode&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="Message"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;messageSecurity &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;authorizationInfo&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="your_authorisation_key"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;messageSecurity&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;securityProperties&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;dataCacheClient&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;dataCacheClients&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;There are also a few bug fixes and code cleanup in there. Thanks to &lt;a href="http://www.linkedin.com/in/corneliutusnea" target="_blank"&gt;Corneliu Tusnea&lt;/a&gt; (creator of &lt;a href="http://onesaas.com/" target="_blank"&gt;OneSaas&lt;/a&gt;) for submitting some really useful changes and bug fixes.&lt;/p&gt;

&lt;p&gt;Hope you enjoy the new features. &lt;/p&gt;

&lt;p&gt;Go get the Nuget package from &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Or download the source code from &lt;a href="https://bitbucket.org/glav/cacheadapter" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7919105" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Component/default.aspx">Component</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Performance/default.aspx">Performance</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/CacheAdapter/default.aspx">CacheAdapter</category></item><item><title>CacheAdapter–V2 Now with memcached support</title><link>http://weblogs.asp.net/pglavich/archive/2011/07/04/cacheadapter-v2-now-with-memcached-support.aspx</link><pubDate>Mon, 04 Jul 2011 04:00:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7854650</guid><dc:creator>Glav</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7854650</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/07/04/cacheadapter-v2-now-with-memcached-support.aspx#comments</comments><description>&lt;p&gt;Previously I blogged about my &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/05/31/cacheadapter-now-a-nuget-package.aspx" target="_blank"&gt;CacheAdapter&lt;/a&gt; project that is available as a &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;Nuget&lt;/a&gt; package and allows you to program against a single interface implementation, but have support for using Memory, ASP.NET Web or &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;Windows AppFabric&lt;/a&gt; cache mechanisms via configuration.&lt;/p&gt;  &lt;p&gt;I am happy to announce that my &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/05/31/cacheadapter-now-a-nuget-package.aspx" target="_blank"&gt;CacheAdapter&lt;/a&gt; now has support for &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt;. Version 2 of the &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;Nuget&lt;/a&gt; package is available &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;here&lt;/a&gt;. Alternatively, all the source code is available &lt;a href="https://bitbucket.org/glav/cacheadapter" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;What this now means is you can write one line of code to get or store an item in the cache, and that code can automatically support using Windows AppFabric, &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt;, MemoryCache or ASP.NET web cache. No code change required.&lt;/p&gt;  &lt;p&gt;I am particularly happy about having &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; support as it means a few things:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Free / Open Source&lt;/strong&gt;: It is a free, well established open source caching engine that is widely used in many applications. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Easy&lt;/strong&gt;: It is easy to setup. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Simple and Cheap&lt;/strong&gt;: It provides an alternative to using &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;Windows AppFabric&lt;/a&gt;. &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; can be a little tricky to setup sometimes. If you are using Windows Azure, &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; is a simple checkbox BUT you need to pay extra for the privilege of using it based on how much you use the cache service. By contrast, &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; can be installed easily on Azure and requires no extra cost whatsoever. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Auto fail over support&lt;/strong&gt;: In addition, Windows &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; has some limitations for a relatively small cache farm. &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; utilises a “lead host” to co-ordinate small cache farms of 3 or less cache servers. If the lead host goes down, they all go down. The &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; implementation has no reliance on any single point of failure so if one &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; node fails, requests will automatically be redirected to the nodes that are alive. If the dead node comes back alive again, it is re-introduced to the cache pool after about 1 minute or so. At worst, it results in a few cache misses. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Note: This release contains a few namespace changes that may break older versions if you are using the objects directly. Namely &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; object support has been moved from the &lt;font face="Courier New"&gt;Glav.CacheAdapter.Distributed&lt;/font&gt; namespace to the &lt;font face="Courier New"&gt;Glav.CacheAdapter.Distributed.AppFabric&lt;/font&gt; namespace. This is to allow differentiation from &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" target="_blank"&gt;AppFabric&lt;/a&gt; and &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; within the distributed namespace.&lt;/p&gt;  &lt;p&gt;In addition, at the request of some users, I have added a simple ‘Add’ method to the &lt;font face="Courier New"&gt;ICacheProvider&lt;/font&gt; interface for ease of use. The interface now looks like this:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2e147624-7d72-4532-adf1-843f23b76723" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;interface&lt;/span&gt;&lt;span style="color: #000000;"&gt; ICacheProvider
{
    T Get&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;T&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey, DateTime absoluteExpiryDate, GetDataToCacheDelegate&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;T&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; getData, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; addToPerRequestCache &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;) &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;where&lt;/span&gt;&lt;span style="color: #000000;"&gt; T : &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    T Get&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;T&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey, TimeSpan slidingExpiryWindow, GetDataToCacheDelegate&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;T&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; getData, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; addToPerRequestCache &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;) &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;where&lt;/span&gt;&lt;span style="color: #000000;"&gt; T : &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; InvalidateCacheItem(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey);
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; Add(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey, DateTime absoluteExpiryDate, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt; dataToAdd);
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; Add(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey, TimeSpan slidingExpiryWindow, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt; dataToAdd);
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; AddToPerRequestCache(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheKey, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt; dataToAdd);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;So that is it. I hope you enjoy using &lt;a href="http://memcached.org/" target="_blank"&gt;memcached&lt;/a&gt; support within the &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/05/31/cacheadapter-now-a-nuget-package.aspx" target="_blank"&gt;CacheAdapter&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7854650" width="1" height="1"&gt;</description></item><item><title>Converting from Webforms view engine to Razor–Some Tips</title><link>http://weblogs.asp.net/pglavich/archive/2011/06/06/converting-from-webforms-view-engine-to-razor-some-tips.aspx</link><pubDate>Sun, 05 Jun 2011 22:16:55 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7819367</guid><dc:creator>Glav</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7819367</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/06/06/converting-from-webforms-view-engine-to-razor-some-tips.aspx#comments</comments><description>&lt;p&gt;Recently, I have had to perform a lot of conversion in an MVC application from using the webforms view engine to the Razor view engine.&lt;/p&gt;  &lt;p&gt;I say “had to” but we didn’t really have to, more wanted to. We wanted the cleaner syntax that razor allows. Since we were going to embark on a bunch of new features involving new pages, we wanted to do this conversion earlier rather than later to prevent excessive rework.&lt;/p&gt;  &lt;p&gt;This post simply summarises most of the issues and tips that were experienced along the way and how we overcame them, so that others can get a clear picture of what is involved should they embark on such an undertaking, and be prepared for any issues.&lt;/p&gt;  &lt;h2&gt;Preparation&lt;/h2&gt;  &lt;p&gt;First off, there are some things you should do prior to starting the conversion to make the process as smooth as possible, and to allow easy resolution of any issues.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Take a copy of your entire source tree and keep it separate to allow for comparison along the way. If you are using HG or GIT, clone your repository to another location. Sure you could look at source control history if you wanted, but its easier to have this code at hand to do side by side comparisons.More importantly though, you can run the backup version to compare HTML output to make sure your conversions are good.      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;In your solution, turn on MVC compiled views. This will tell the compiler to compile your views and you will catch any errors whenever you compile. Very handy and saves sometime. Unfortunately, it does add some time to the build process. If you have a lot of views, this could be lengthy, so you may want to disable this after the conversion is complete. To enable compiled views:      &lt;ul&gt;       &lt;ul&gt;         &lt;li&gt;Right click on your project in solution explorer, and select Unload Project. &lt;/li&gt;          &lt;li&gt;One its unloaded, right click on it again and select ‘Edit Project. The project XML will load in the editor window. &lt;/li&gt;          &lt;li&gt;Locate the following &lt;/li&gt;       &lt;/ul&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:a70305a2-4632-46a9-9c54-d68c8157d44e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MvcBuildViews&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;MvcBuildViews&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;and change it to &lt;/p&gt;
&lt;/blockquote&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:54d2cb07-33f3-451c-9288-c47f06bde186" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MvcBuildViews&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;MvcBuildViews&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;ul&gt;
      &lt;li&gt;Save the file. Then right click on the project again and select ‘Reload Project’ &lt;/li&gt;

      &lt;li&gt;Now when you compile, your views will also be compiled. &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/ul&gt;

  &lt;li&gt;Download the &lt;a href="http://blogs.telerik.com/blogs/posts/11-01-19/webforms_to_razor_view_converter_tool.aspx" target="_blank"&gt;aspx2razor&lt;/a&gt; conversion tool from Telerik which does a reasonable job of converting your ASPX views into razor views. It probably wont do it all for you,but it removes a good deal of work. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Performing the actual conversion&lt;/h2&gt;

&lt;p&gt;This is the easy part. Simply run the conversion tool over your project. You can do this by running the tool against your base views directory and have it recursively convert all files it founds in all directories to their razor counterparts. Something like this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f361e519-dd8c-4ec8-b809-970cb139ab41" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;aspx2razor.exe c:\MyProject\MyViews\&lt;/span&gt;&lt;span style="color: #000000;"&gt;*&lt;/span&gt;&lt;span style="color: #000000;"&gt;.cshtml MyOutputDirectory &lt;/span&gt;&lt;span style="color: #000000;"&gt;-&lt;/span&gt;&lt;span style="color: #000000;"&gt;r&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;You will then need to copy the files from the output directory into your solution and ensure they are included in the project. Make sure you delete all the existing ASPX files as having both of these file types present can cause problems.&lt;/p&gt;

&lt;p&gt;So that’s it. Job done right?&lt;/p&gt;

&lt;h2&gt;Testing and Fixing&lt;/h2&gt;

&lt;p&gt;Now the fun begins. The conversion tool works reasonably well, but it has its problems. Here are some of the issues you will find.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The conversion tool does not support master pages, so don’t expect them to be converted. Roll up your sleeves and do those manually. Even though the tool does not support master pages, it will blindly convert anything you tell it to so it will attempt to convert a master page if one exists in the set of input files. Don’t be tempted to use a partially converted master page if there is one as it will usually not convert properly, putting in an incorrect &lt;a href="mailto:&amp;lsquo;@inherits&amp;rsquo;"&gt;‘@inherits’&lt;/a&gt; directive which just causes more confusion. Start from scratch and do the master pages manually. &lt;/li&gt;

  &lt;li&gt;Sometimes the conversion tool completely misses the server side tags, particularly when embedded in script tags like this: &lt;/li&gt;
&lt;/ul&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f2336762-e26a-4f55-b6bb-3d5b404f2474" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;script &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; language&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="javascript"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; src&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="&amp;lt;%: Url.Content("&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;~/Content/Scripts/jQuery/jshashtable.js") %&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt;"&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Embedded server tags can get completely messed up when converting to razor. As an example, the following snippet: &lt;/li&gt;
&lt;/ul&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9568ccc5-e4fe-40a2-9535-1d030682ede3" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;class="item &lt;/span&gt;&lt;span style="background-color: #FFFF00; color: #000000;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt;: isParentDate ? &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;""&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt; : &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;"&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;child-date &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;"&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background-color: #FFFF00; color: #000000;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="background-color: #FFFF00; color: #000000;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt;: item.IsReconciled ? &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;"&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;reconciled &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;"&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt; : &lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #800000;"&gt;""&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background-color: #FFFF00; color: #000000;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;"&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;gets converted to the following razor equivalent:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:edcd4900-db79-4595-acb1-b36659bdaa0e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;item @isParentDate ? &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #800000;"&gt; : &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;child&lt;/span&gt;&lt;span style="color: #000000;"&gt;-&lt;/span&gt;&lt;span style="color: #000000;"&gt;date &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;@item.IsReconciled ? &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;reconciled &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt; : &lt;/span&gt;&lt;span style="color: #800000;"&gt;"""&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;which is obviously incorrect and results in simple text being output to the HTML, not the expected class names. Ideally, this should be refactored into amore explicit code block, something like this:&lt;/p&gt;

  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8af3837b-20e8-4d0b-addf-8cf3d2ebb819" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;@{ 
  var divClass &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;.Format(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;item {0}{1}&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, isParentDate &lt;/span&gt;&lt;span style="color: #000000;"&gt;?&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;.Empty : &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;child-date &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, item.IsReconciled &lt;/span&gt;&lt;span style="color: #000000;"&gt;?&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;reconciled &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; : &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
}
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;@divClass&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;“Tight” concatenation of server tags like this: &lt;/li&gt;
&lt;/ul&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:888deb4d-124e-4951-9b57-4244fdd1e3f1" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;input &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="hidden"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; id&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="itemAmount&amp;lt;%: Model.BankFeed.Id %&amp;gt;"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;get converted to this:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c9519885-47b8-4bbb-bbf8-0d038fadeee0" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;input &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="hidden"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; id&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="itemAmount@Model.BankFeed.Id"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;which is not right and just renders the text. Again, something more explicit is required such as:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:82b28cb7-f367-4dfc-a18d-ecf1a60b5b62" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;@{ 
  var controlId = string.Format("itemAmount{0}", Model.Id);
}
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;input &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="hidden"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; id&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="@controlId"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;One last tip. Use the “original” copy of your site and run it up in a browser, do the same with the converted site. For each view that is converted, it is worth doing a “source view” of original and converted page from the browser to ensure you are getting the same output. This is particularly important for scripts and CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is about it for most of the issues I came across. You will no doubt experience some variations from the examples above, but the set of issues presented here should at least allow you to be prepared for what the actual conversion effort is going to be. &lt;/p&gt;

&lt;p&gt;Hopefully, this article helps you to efficiently convert your projects into the wonderful world of razor &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/pglavich/wlEmoticon-smile_0D74FC15.png" /&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7819367" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Razor/default.aspx">Razor</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Webforms/default.aspx">Webforms</category></item><item><title>CacheAdapter–Now a Nuget package</title><link>http://weblogs.asp.net/pglavich/archive/2011/05/31/cacheadapter-now-a-nuget-package.aspx</link><pubDate>Tue, 31 May 2011 06:12:05 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7809931</guid><dc:creator>Glav</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7809931</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/05/31/cacheadapter-now-a-nuget-package.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Note: Link to Wiki is &lt;/em&gt;&lt;a href="https://bitbucket.org/glav/cacheadapter/wiki/Home" target="_blank"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A while ago, I &lt;a href="http://weblogs.asp.net/pglavich/archive/2010/10/13/caching-architecture-testability-dependency-injection-and-multiple-providers.aspx" target="_blank"&gt;blogged about a personal project&lt;/a&gt; around caching that allowed you to abstract away the underlying cache mechanism, and use whatever cache you wanted. Through simple configuration, you can choose to use either the memory cache provided by System.Runtime.Caching in .Net 4, the traditional ASP.NET web cache, or you can use the Windows AppFabric caching to taker advantage of distributed caching.&lt;/p&gt;  &lt;p&gt;Well, its now &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;a package on Nuget&lt;/a&gt; that you can easily install and use immediately. You can grab it from &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/install-package-image_51005C96.png"&gt;&lt;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="install-package-image" border="0" alt="install-package-image" src="http://weblogs.asp.net/blogs/pglavich/install-package-image_thumb_43B9D383.png" width="539" height="62" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Update: This package uses the &lt;/em&gt;&lt;a href="http://www.opensource.org/licenses/MS-PL" target="_blank"&gt;&lt;em&gt;Microsoft Public Licence (MS-PL)&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Just as a recap, you can use this cache adapter like this:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8015f111-d5a6-42a2-9cab-180cc895bbec" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;var data1 &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; cacheProvider.Get&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;SomeData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;cache-key&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, DateTime.Now.AddSeconds(&lt;/span&gt;&lt;span style="color: #800080;"&gt;3&lt;/span&gt;&lt;span style="color: #000000;"&gt;), () &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
{
    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; This is the anonymous function which gets called if the data is not in the cache.
    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; This method is executed and whatever is returned, is added to the cache with the
    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; passed in expiry time.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;... =&amp;gt; Adding data to the cache... 1st call&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
    var someData &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; SomeData() { SomeText &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;cache example1&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, SomeNumber &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt; };
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; someData;
});
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;(Note: You will get a small example .cs file included in your project that contains this example usage when you install the package)&lt;/p&gt;

&lt;p&gt;You can see in the example, that you can request the data, and provide a lambda that retrieves that data if its not in the cache. The data gets added to the cache once the lambda has been executed to retrieve the data from the source. Also, the data that is returned is strongly typed. It is not a generic object that you then need to cast.&lt;/p&gt;

&lt;p&gt;Additionally, you can set the type of cache used by one line of configuration:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b8a200ab-b537-40e5-a221-02b230ff0de9" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting name&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;CacheToUse&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;String&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Memory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;If I wanted to use the ASP.NET Web cache, I could simply set the config item like so:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b3a42a7a-9f23-455a-a9e6-1ba2fb55357c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting name&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;CacheToUse&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;String&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Web&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;And if I wanted to use the AppFabric distributed cache (assuming it has been installed on the system), then I can simply set the config like so:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e7d08a9b-a6e7-44f7-8135-323982474dbf" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting name&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;CacheToUse&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;String&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;AppFabric&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;The package references the required AppFabric client assemblies for you. This means you can write a web application today using this package and use the traditional ASP.NET cache. Then we you are ready, install AppFabric, setup a cache cluster, change the configuration to enable AppFabric and you are away. No code changes to your app.&lt;/p&gt;

&lt;h4&gt;Using AppFabric&lt;/h4&gt;

&lt;p&gt;To use AppFabric, there are a few extra things to do by way of Infrastructure. Obviously, you need to &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=467e5aa5-c25b-4c80-a6d2-9f8fb0f337d2" target="_blank"&gt;download and install it&lt;/a&gt;. Then you need to setup your cache cluster via the wizard when you install it (or via powershell if you choose). During this process you will be creating some cache nodes and you need to create a named cache for your application. This can be done via powershell using the&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;font face="Courier New"&gt;New-Cache {cachename}&lt;/font&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;powershell command. In addition, you will need to ensure that the user that will be accessing the cache has access to it. Again, this can be done from powershell via the:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;font face="Courier New"&gt;Grant-CacheAllowedClientAccount {account}&lt;/font&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is some additional config you will need to do as well. In the application config file you will need to change the following entries to match your configured infrastructure:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:7ef1c92c-45d6-4080-a66f-3bc54c21d57f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting name&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;DistributedCacheServers&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;String&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;localhost:&lt;/span&gt;&lt;span style="color: #800080;"&gt;22223&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting name&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;DistributedCacheName&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; serializeAs&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;String&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MyCache&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;value&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000;"&gt;setting&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;The “&lt;font face="Courier New"&gt;DistributedCacheServers&lt;/font&gt;” setting can be a comma separated list of servers and ports that the cache client (ie. your app) will communicate with. This can be one or as many comma separated entries as you like and depends on your cache cluster config.&lt;/p&gt;

&lt;p&gt;The “&lt;font face="Courier New"&gt;DistributedCacheName&lt;/font&gt;” is the name of the cache you have setup in the cache cluster for your app. (Detailed above)&lt;/p&gt;

&lt;h4&gt;Final Notes&lt;/h4&gt;

&lt;p&gt;Before I published this package, I cleaned it up a bit as I have been using it on a current project and I didn’t like a number of ways I implemented things initially. Instead of multiple assemblies, everything is in the one assembly. &lt;/p&gt;

&lt;p&gt;Also, I removed the use of Unity as a mechanism for dependency injection and implemented a very very simple method which uses no particular dependency injection implementation. I did this because everyone wants to do DI (Dependency Injection) using their favourite implementation whether this be Unity, Autofac, Ninject, Castle Windsor etc. etc. So I opted for something that does the job, it is not what a purist would be happy with, but is dead simple to rip out and change which is what I expect most people would do.&lt;/p&gt;

&lt;p&gt;Finally, because all cache access is via an interface, it allows for easy testability.&lt;/p&gt;

&lt;p&gt;So &lt;a href="http://nuget.org/List/Packages/Glav.CacheAdapter" target="_blank"&gt;go grab it&lt;/a&gt;. Or you can &lt;a href="https://bitbucket.org/glav/cacheadapter" target="_blank"&gt;download the source code form here&lt;/a&gt; and change it to your hearts content. Its actually a relatively simple implementation and it would be easy to plug in any underlying cache implementation should you wish.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7809931" width="1" height="1"&gt;</description></item><item><title>Diskeeper–a short review</title><link>http://weblogs.asp.net/pglavich/archive/2011/05/16/diskeeper-a-short-review.aspx</link><pubDate>Sun, 15 May 2011 22:23:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7792367</guid><dc:creator>Glav</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7792367</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/05/16/diskeeper-a-short-review.aspx#comments</comments><description>&lt;p&gt;I have been lucky enough to be ASP.NET MVP for a number of years now. One of the perks of that is you get access to free licences of software such as &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt;. This piece of software keeps your disks running as smooth as they possibly can.&lt;/p&gt;  &lt;p&gt;I have been using &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt; for around 2 months now and am pretty impressed. It silently does its thing in the background without you having to touch anything. One of the newest and also one of my favourite features is the automatic defrag capability.You don’t have to launch a defrag application and have it run on your system or schedule it to run periodically, as &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt; performs this operation all the time, in the background for all disk operations. Basically, you just use your system like normal, and it just magically gets defragmented, all the time. Nice.&lt;/p&gt;  &lt;p&gt;I have 2 disks in my system. A SSD (Solid State Drive) as my primary ( C: ) drive, and a 5200rpm 320Gb hard disk as my secondary data drive ( D: ). After installing &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt;, I have noticed a significant difference in the performance of the secondary drive in particular. I imagine because it is the slowest disk and because it stands to benefit the most. The SSD is fast anyway, so it is much harder to notice any difference. I have noticed a small difference, but it’s only slight compared to the secondary ( spinning rust ) drive.&lt;/p&gt;  &lt;p&gt;I should mention that in order for &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt; to work with SSD hardware, you need a special edition of &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt; with an add-on called Hyper-fast that takes into account the SSD unit and has special algorithms that are designed to optimise SSD operation.&lt;/p&gt;  &lt;p&gt;For those interested in the actual metrics, &lt;a href="http://www.diskeeper.com" target="_blank"&gt;Diskeeper&lt;/a&gt; provides an easy to use management console that displays your current system improvements. The initial display is shown below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/image_7E5F61B0.png"&gt;&lt;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://weblogs.asp.net/blogs/pglavich/image_thumb_5F0C9510.png" width="502" height="330" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The management console offers a number of ways to look at what has been done to your disks and how it has been performing. I find the history view particularly interesting as it proves a look at how the disk is being used and optimised over time.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/image_09985021.png"&gt;&lt;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://weblogs.asp.net/blogs/pglavich/image_thumb_074BA198.png" width="506" height="332" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So would I recommend it? Yes, and this is not simply because I have been given a free licence and feel obligated to do so. It is particularly useful if you have standard hard disks regardless of how fast they spin. You will notice a much smoother and responsive system as a result. For SSD owners, it is still worthwhile but the benefits are less because of the inherent speed in SSD units. For a system with a mix of SSD and hard disks, it works beautifully.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7792367" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Entity Framework and the PreApplicationStartMethod attribute</title><link>http://weblogs.asp.net/pglavich/archive/2011/05/06/entity-framework-and-the-preapplicationstartmethod-attribute.aspx</link><pubDate>Fri, 06 May 2011 03:09:05 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7778092</guid><dc:creator>Glav</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7778092</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/05/06/entity-framework-and-the-preapplicationstartmethod-attribute.aspx#comments</comments><description>&lt;p&gt;Recently, while implementing an EntityFramework data model into a new application, I thought I’d add some caching functionality early, to establish a framework going forward. I added the DBML (generated from a database), and added in my funky caching layer (which will be distributed as a Nuget package soon) that allows caching to be configurable switching between in memory, ASP.NET cache and AppFabric caching.&lt;/p&gt;  &lt;p&gt;Anyway, I added some repository methods to grab data from the database. All good. I added my caching layer to that so that a bunch of reference data was cached, again all good.&lt;/p&gt;  &lt;p&gt;Now this application is a .NET 4/ASP.NET MVC 3 application and I was using the &lt;font face="Courier New"&gt;&lt;a href="http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx" target="_blank"&gt;PreApplicationStartMethod&lt;/a&gt;&amp;#160;&lt;/font&gt;attribute to specify a class method that is executed before anything else in the application. Something like this:-&lt;/p&gt;  &lt;p&gt;In the&lt;font face="Courier New"&gt; AssemblyInfo.cs&lt;/font&gt; file I had this attribute declaration:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:8e1a0c13-a63c-42da-9617-8a6c6c12d8e7" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;[assembly: PreApplicationStartMethod(typeof(WebAppStart), &amp;quot;PreStartInitialise&amp;quot;)]&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;And in the &lt;font face="Courier New"&gt;WebAppStart.cs&lt;/font&gt; file I had this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:be106a89-b2ae-4658-8e0d-43a5444e379a" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; WebAppStart
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; PreStartInitialise()
    {
        RegisterWebDependencies();
    }
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;This all worked well. Then I thought, well rather than let the first user of the application cause the cache to get primed/filled, I would simply make a call to a method I had already to prefill the cache:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f8b38c55-48be-4ecd-98a1-35b89303571c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; PreStartInitialise()
{
    RegisterWebDependencies();
    PrimeCache();
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Seems ok so far, but alas no. Apparently, you cannot use the EntityFramework from within a method invoked by the &lt;font face="Courier New"&gt;&lt;a href="http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx" target="_blank"&gt;PreApplicationStartMethod&lt;/a&gt;&lt;/font&gt; attribute. What you will get is an exception message like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/RealExceptionMsg_1CEF7FCA.png"&gt;&lt;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="RealExceptionMsg" border="0" alt="RealExceptionMsg" src="http://weblogs.asp.net/blogs/pglavich/RealExceptionMsg_thumb_3EF7DB90.png" width="546" height="133" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The solution was easy enough for me, I just moved the PrimeCache method to the &lt;font face="Courier New"&gt;Application_Start&lt;/font&gt; event within the &lt;font face="Courier New"&gt;Global.asax.cs&lt;/font&gt; file. However, what made this error, let’s say “interesting” is that I was developing an azure application. What then happens is you get an error that seemingly has nothing to do with the root cause. So when developing running in debug mode for an azure application you get the following exception:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/ExceptionOnRunningApp_717B3902.png"&gt;&lt;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="ExceptionOnRunningApp" border="0" alt="ExceptionOnRunningApp" src="http://weblogs.asp.net/blogs/pglavich/ExceptionOnRunningApp_thumb_33BE2B79.png" width="554" height="164" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It seems to point to some issue with the connection string which is absolute rubbish and leads you to nowhere. If you happen to try and run this without attaching a debugger, then you simply get an exception dialog stating that the windows azure web role has stopped working.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/ExceptionMsg_30C8C6C6.png"&gt;&lt;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="ExceptionMsg" border="0" alt="ExceptionMsg" src="http://weblogs.asp.net/blogs/pglavich/ExceptionMsg_thumb_194E1295.png" width="467" height="239" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Nice.&lt;/p&gt;

&lt;p&gt;So, the moral to this story. Don’t use EntityFramework within a method defined using the &lt;font face="Courier New"&gt;&lt;a href="http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx" target="_blank"&gt;PreApplicationStartMethod&lt;/a&gt; &lt;/font&gt;attribute. If developing an azure app and you get this error, do not believe what you are told. Move the EntityFramework code to somewhere later in the lifecycle and you will be good.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7778092" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Mix11–Day 2 Sessions</title><link>http://weblogs.asp.net/pglavich/archive/2011/04/14/mix11-day-1-sessions.aspx</link><pubDate>Wed, 13 Apr 2011 20:49:42 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7756101</guid><dc:creator>Glav</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7756101</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/04/14/mix11-day-1-sessions.aspx#comments</comments><description>&lt;p&gt;I blogged &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/04/12/mix-11-bootcamp-day.aspx"&gt;here&lt;/a&gt; about my Mix11 bootcamp sessions, and &lt;a href="http://weblogs.asp.net/pglavich/archive/2011/04/14/mix11-day-1-sessions.aspx"&gt;here&lt;/a&gt; about my Mix11 day 1 keynote and sessions. To continue the theme, here are some thoughts and opinions around Day 2.&lt;/p&gt;  &lt;h2&gt;Keynote #2&lt;/h2&gt;  &lt;p&gt;This keynote started a little slow with some apologies and explanations around delays in Windows Phone 7 updates coming. Necessary but unexciting. After that though, things moved along well. Lots of great new features coming to Windows Phones in the form of the “mango” update to come soon. Things like better much performance, SQL databases on the phone, better multitasking. You can read about all the features &lt;a href="http://geekswithblogs.net/campuskoder/archive/2011/04/13/144848.aspx"&gt;here&lt;/a&gt;. One thing that I personally liked was the fact that IE9 will be the browser on Windows Phone and replace the current klunky browser version. This means I can target Windows Phone 7 with HTML 5 apps like I can with iPhone and Android. Nice.&lt;/p&gt;  &lt;p&gt;All the new features that will come with the Mango update will really make WP7 a much more polished device.&lt;/p&gt;  &lt;p&gt;The developer tools update for Windows Phone 7 look just fantastic. Really polished and it will be a real big gain. Being able to emulate titling your phone, gestures such as shaking the phone, and other smaller items such as placing breakpoints on bindings in XAML markup will make development so much nicer. Microsoft have done a huge amount of work here and it shows.&lt;/p&gt;  &lt;p&gt;Silverlight 5 was announced and the beta is available for download from &lt;a href="http://www.silverlight.net/getstarted/silverlight-5-beta/"&gt;here&lt;/a&gt;. There are a huge number of improvements in this new release and it looks really nice. &lt;/p&gt;  &lt;p&gt;Kinect played a big part in this keynote with some awesome example of what the community has done with the Kinect. In particular, a fully mobile lounge chair, controlled via hand gestures and the Kinect. Also, the Microsoft Telescope demo using the Kinect was excellent. All attendees were also given a free Kinect which was fantastic and obviously made everyone happy.&lt;/p&gt;  &lt;p&gt;A great keynote overall.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here are some thoughts on the sessions I have attended.&lt;/p&gt;  &lt;h2&gt;Douglass Crockford: ECMAScript 5: The New Parts&lt;/h2&gt;  &lt;p&gt;Its Douglass Crockford. End of story. If Javascript is your thing, then you really can’t go past this to get some insight into where the language is going, from the man himself.&lt;/p&gt;  &lt;h2&gt;Back To Square One&lt;/h2&gt;  &lt;p&gt;This talk was presented by Nishant Kothary and it held almost no technical content. A little but not much. You might think that this is a negative thing but that is not the case. I found this talk exceptional and provided many insights into why and how we think like we do. It looked at why some projects have failed, and why some succeeded. In addition, there was some really interesting material around left vs right hemisphere brain function and how that relates to developers and designers.&lt;/p&gt;  &lt;p&gt;It was a really interesting presentation and I found it one of the best and most refreshing of Mix. Entertaining, engaging and informative. Highly recommended.&lt;/p&gt;  &lt;p&gt;Go download or stream the content from &lt;a href="http://live.visitmix.com"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7756101" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Mix/default.aspx">Mix</category></item><item><title>Mix 11–Bootcamp Day</title><link>http://weblogs.asp.net/pglavich/archive/2011/04/12/mix-11-bootcamp-day.aspx</link><pubDate>Mon, 11 Apr 2011 22:40:51 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7752976</guid><dc:creator>Glav</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7752976</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/04/12/mix-11-bootcamp-day.aspx#comments</comments><description>&lt;p&gt;I have been lucky enough to get to the Mix11 event this year (many thanks to my awesome company &lt;a href="http://www.saasu.com/"&gt;Saasu&lt;/a&gt;) and have been attending the bootcamps here at &lt;a href="http://live.visitmix.com"&gt;Mix&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/events/mix/mix11/CMP02"&gt;First one was Design, Content, Code: Start to Finish&lt;/a&gt; with Roman Blagovirnyy, Anthony Franco, Cindy Vanover Tony Walt and Chad Bakeman of &lt;a href="http://www.effectiveui.com/"&gt;effective ui&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;It presented an overview of the start to finish process of a rich interactive site, utilising a hybrid approach of HTML 5 and Silverlight. Traditional ASP.NET webforms was chosen over MVC with the reason cited as the extra complexity of MVC was unnecessary and provided no benefit.&lt;/p&gt;  &lt;p&gt;This session was a good session for a few reasons.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It presented a project from start to finish and described the challenges involved. &lt;/li&gt;    &lt;li&gt;Talked a good deal about the design process for such a rich and interactive site. While this team had a number of designers and UX savvy people, the concepts, processes and more importantly, the risks could be utilised and taken into account in any sized team or project.      &lt;ul&gt;       &lt;li&gt;For example, the use of nodes to build high level navigation concepts, then further drilling into these nodes in an intuitive way to build out the rest of the navigational elements of the site, which was finally formed into a set of wireframes. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Talked a lot about the technology used, including such elements as Silverlight, 3D rendering (think depth of field, particle systems, lens flares etc,…). Items such as considerations when combining and synchronising multiple videos, usage of HTML 5 video functionality is not as easy as its “standardised inclusion” is meant to be, compression and bit rate considerations amongst others. &lt;/li&gt;    &lt;li&gt;Provided insight into how other company and people do things. This is probably the most valuable as everyone does things their own way, even if they follow a specific process or methodology, it is usually tailored in some way to meet the needs of the business, company and client. It is extremely valuable to gain this insight as it is experience based and this what is often hard to get without going through some pain first. The pain points were not too dissimilar from most peoples, client issues (although the client was the navy/military so presented extra challenges), integrating all the media into the site in a usable and intuitive way, tight deadlines,unforseen technical issues, as well as a few others. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;All in all a good session with lots to learn.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7752976" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Mix/default.aspx">Mix</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/HTML+5/default.aspx">HTML 5</category></item><item><title>Sydney Architecture User Group - It has come to an end</title><link>http://weblogs.asp.net/pglavich/archive/2011/03/22/sydney-architecture-user-group-it-has-come-to-an-end.aspx</link><pubDate>Tue, 22 Mar 2011 03:57:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7729234</guid><dc:creator>Glav</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7729234</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/03/22/sydney-architecture-user-group-it-has-come-to-an-end.aspx#comments</comments><description>&lt;p&gt;Unfortunately, the &lt;a href="http://thesaug.org"&gt;Sydney Architecture User Group&lt;/a&gt; that &lt;a href="http://omarbesiso.typepad.com/"&gt;Omar Besiso&lt;/a&gt; and myself run in Sydney, is closing its doors.&lt;/p&gt; &lt;p&gt;It has been running for around 2 years now and we have had some great sessions, however there are a number of factors that have caused us to make this decision.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Primarily, we lost our funding. Datacom (the company I used to work for and where Omar still works) were originally kind enough to foot the bill for the venue and food (which was substantial), however Datacom Software Solutions are undergoing their own financial issues and as such, had to stop funding. While Microsoft also provides some funding, it was not enough to cater for the current venue and we did not have another venue to go to. Now that I work for the awesome &lt;a href="http://saasu.com"&gt;Saasu.com&lt;/a&gt;, its a little hard for me to try and push this issue.&lt;/li&gt;
&lt;li&gt;Secondly, it was getting harder to organise speakers. Presenting takes time and effort, and the availability of speakers was getting low. The last few months meant that Omar and myself would often have to juggle presenting.&lt;/li&gt;
&lt;li&gt;Lastly, interest in the group was slowly declining. We have seen this a lot lately where some user groups are either closed down, or become part of a larger group in order to survive. I think this may be indicative of the community in general. There are a lot of user groups locally in Australia. Probably too much. The ones that survive seem to specialise in certain areas. In addition, the amount of online technical learning content available means a user group has to offer something different to be effective.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, we close our doors. However, we are looking at re-inventing a new learning mechanism soon. Something that differs to a user group and can offer value that traditional user groups and online content cannot provide.&lt;/p&gt;
&lt;p&gt;Stay tuned...&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7729234" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/General/default.aspx">General</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Architecture/default.aspx">Architecture</category></item><item><title>My Mix11 Proposal</title><link>http://weblogs.asp.net/pglavich/archive/2011/01/27/my-mix11-proposal.aspx</link><pubDate>Wed, 26 Jan 2011 20:51:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7690526</guid><dc:creator>Glav</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7690526</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2011/01/27/my-mix11-proposal.aspx#comments</comments><description>&lt;p&gt;I only submitted one session for consideration to present at &lt;a href="http://live.visitmix.com/" target="_blank"&gt;Mix&lt;/a&gt; this year. Unfortunately it was not shortlisted and is consequently not open to &lt;a href="http://live.visitmix.com/OpenCall" target="_blank"&gt;voting&lt;/a&gt; currently on the site.&lt;/p&gt;  &lt;p&gt;However, I thought I might post it here to gain some feedback from others as to how I might refine or change it. Maybe it is just something people are not interested in and I have taken a wrong direction. Perhaps you might be interested in me presenting this at your user group?&lt;/p&gt;  &lt;p&gt;At any rate, the session abstract is below and would love your feedback.&lt;/p&gt;  &lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;h4&gt;Title: There is no Web: HTML5 Offline capabilities&lt;/h4&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Abstract&lt;/u&gt;&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;HTML 5 offers many new capabilities to the standardised web space. The majority of this session will focus on a few capabilities geared towards allowing your web applications to function when the web is not available or otherwise pre-occupied. For a lot of developers, this has not been too much of a consideration because of the limited ability to deal with it, but with HTML 5 this can all change. We will look at how HTML 5 makes it easier to detect your offline/online status and also look at a way to to construct your application to take this into account and provide a seamless experience for your users. We will look at constructing components to provide a better network detection status, offline storage approaches, integration with ASP.NET MVC, and to top it all off, will utilise the RavenDB (NoSQL) document storage engine just for some fun. If you want to see some of the techniques and pitfalls of HTML 5 offline capabilities, combined with ASP.NET MVC and NoSQL, then this talk is for you.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7690526" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Mix/default.aspx">Mix</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/HTML+5/default.aspx">HTML 5</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/NoSQL/default.aspx">NoSQL</category></item><item><title>ScriptHelper–For MVC and WebForms projects</title><link>http://weblogs.asp.net/pglavich/archive/2010/11/18/scripthelper-for-mvc-and-webforms-projects.aspx</link><pubDate>Thu, 18 Nov 2010 06:38:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7646213</guid><dc:creator>Glav</dc:creator><slash:comments>30</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7646213</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2010/11/18/scripthelper-for-mvc-and-webforms-projects.aspx#comments</comments><description>&lt;p&gt;This issue might seem minor but I always forget the names (exact naming) or number of script files I need to get some features working in MVC or Webforms. In addition, in my applications that require a specific client side feature, I might need a series of dependent scripts to make it work. Failing to include all of them often gives ambiguous errors or the functionality or feature just doesn't work.&lt;/p&gt;  &lt;p&gt;To that end, I have created a ScriptHelper to allow me to express those dependencies as a singular name and have all the script dependencies (or CSS) emitted for me. &lt;/p&gt;  &lt;p&gt;The library is currently hosted on bitbucket here &lt;a href="http://bitbucket.org/glav/mvc-script-dependency-extension"&gt;http://bitbucket.org/glav/mvc-script-dependency-extension&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The idea is that you can express your Javascript and CSS dependencies into a separate file and pretty much call it what you want. Then, in your pages, simply the reference the dependencies by name and everything you need is pulled in for you.&lt;/p&gt;  &lt;p&gt;The ScriptHelper I have written is a little raw, but you can define an XML file that expresses script names and its dependencies. The script helper then allows you to provide that single name and all dependent scripts are emitted in the page.&lt;/p&gt;  &lt;p&gt;For example, in the page you can do:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ScriptHelper.RequiresScript(ScriptName.jqueryValidateUnobtrusive) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;Or&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ScriptHelper.RequiresScript(“jQuery-validate-unobtrusive”) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;And you would get&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;='text/javascript'&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;='/Scripts/jquery-1.4.1.js'&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/jquery.validate.js'&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/jquery.validate.unobtrusive.js'&lt;/span&gt;&amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;Additionally, you could do:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ScriptHelper.RequiresScript(&lt;span class="str"&gt;&amp;quot;All&amp;quot;&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;And you would get the following emitted into your page:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;='text/javascript'&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;='/Scripts/jquery-1.4.1.js'&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/MicrosoftAjax.js'&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/MicrosoftMvcAjax.js'&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/jquery.validate.js'&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/jquery.validate.unobtrusive.js'&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&lt;span class="str"&gt;'text/javascript'&lt;/span&gt; src=&lt;span class="str"&gt;'/Scripts/MicrosoftMvcValidation.js'&lt;/span&gt;&amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;The dependency file looks something like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependencies&lt;/span&gt; &lt;span class="attr"&gt;ReleaseSuffix&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;min&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DebugSuffix&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;debug&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;jQuery-validate-unobtrusive&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;js&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;~/Scripts/jquery.validate.unobtrusive.js&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;jquery&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;jQuery-validate&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;jQuery-validate&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;js&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;~/Scripts/jquery.validate.js&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;jquery&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;jQuery&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;js&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;~/Scripts/jquery-1.4.1.js&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;— rest of dependencies …. --&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;The &lt;font face="Courier New"&gt;ReleaseSuffix&lt;/font&gt; and &lt;font face="Courier New"&gt;DebugSuffix&lt;/font&gt; also act to rename a dependency file that is output to the page. These are not mandatory but it is not uncommon to host debug versions of your scripts when doing development and release/minified versions of your scripts in production. So for example, if we have a script file dependency defined as &lt;font face="Courier New"&gt;Something.js&lt;/font&gt;, then it will be renamed to &lt;font face="Courier New"&gt;Something.min.js&lt;/font&gt; in release mode and &lt;font face="Courier New"&gt;Something.debug.js&lt;/font&gt; in debug mode when output to the page. If not specified, the emitted dependency is left as is.&lt;/p&gt;

&lt;p&gt;Finally, you can also specify multiple dependencies on the same line like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ScriptHelper.RequiresScript(&lt;span class="str"&gt;&amp;quot;Microsoft-Mvc-Validation&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;jQuery&amp;quot;&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;And all dependent scripts will be included for you without duplicating anything. Obviously the script names must be the same as what is defined in the script dependency file. I have used a static class to hold these constants and you could easily substitute your own as its just strings.&lt;/p&gt;

&lt;p&gt;It also supports expressing CSS dependencies. For example, with the following dependency definitions:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SiteWideStyle&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;css&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;~/Content/Site.css&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HomeStyle&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;css&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;~/Content/Home.css&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ScriptFile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;SiteWideStyle&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;RequiredDependencies&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Dependency&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;You can then include the following in your &amp;lt;head&amp;gt; section of your pages&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ScriptHelper.RequiresScript(&lt;span class="str"&gt;&amp;quot;HomeStyle&amp;quot;&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;And you would get&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;='/Content/Site.css'&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;='stylesheet'&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;='text/css'&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;='/Content/Home.css'&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;='stylesheet'&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;='text/css'&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.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; }&lt;/style&gt;

&lt;p&gt;Currently, the ScriptHelper I have written supports resolving the dependency file in a few local locations, but I plan on extending it support remote locations via HTTP.&lt;/p&gt;

&lt;p&gt;This type of thing could reduce multiple script include to a single line in a web page or view. In addition, you could have dependency files centrally located on a remote server either in the cloud or internal to your organisation, so that dependencies are always resolved via this file which can be maintained and updated as new dependencies and/or later versions of the scripts are available or required.&lt;/p&gt;

&lt;p&gt;There is also nothing stopping you from naming your dependencies more component oriented in nature. For example you might name a dependency “AjaxGrid”, and that may load in jQuery core script, jQuery UI custom scripts, as well as some of your own custom scripts required to get this component working.&lt;/p&gt;

&lt;p&gt;I have been using this library primarily with ASP.NET MVC projects, but it is just a set of static methods that could also be used within an ASP.NET Webforms application as well.&lt;/p&gt;

&lt;p&gt;Feel free to leave comments/issues on the hosting site here &lt;a href="http://bitbucket.org/glav/mvc-script-dependency-extension"&gt;http://bitbucket.org/glav/mvc-script-dependency-extension&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7646213" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Component/default.aspx">Component</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Web+2.0/default.aspx">Web 2.0</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/Community+News/default.aspx">Community News</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET+AJAX/default.aspx">ASP.NET AJAX</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/AJAX+Control+toolkit/default.aspx">AJAX Control toolkit</category></item><item><title>Caching Architecture–Testability, Dependency Injection and Multiple Providers</title><link>http://weblogs.asp.net/pglavich/archive/2010/10/13/caching-architecture-testability-dependency-injection-and-multiple-providers.aspx</link><pubDate>Wed, 13 Oct 2010 10:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7626328</guid><dc:creator>Glav</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7626328</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2010/10/13/caching-architecture-testability-dependency-injection-and-multiple-providers.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Note: Link to Wiki is &lt;/em&gt;&lt;a href="https://bitbucket.org/glav/cacheadapter/wiki/Home" target="_blank"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This article assumes familiarity with caching in .Net and dependency injection.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Update: Fixed broken links and updated some text based on feedback.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;One of the things I have always stated is that caching is important to every applications performance. In many of the applications I design and work on, I like to introduce a caching layer from the outset, and ensure it is part of the vertical slice that I typically provide as an application blueprint.&lt;/p&gt;  &lt;p&gt;Obviously we want to ensure that all this caching magic does not introduce hard dependencies to the underlying caching mechanism. For example, the ASP.NET caching engine is fantastic at what it does, however if you are writing components that make use of it, then they become hard to test as you need to introduce lots of &lt;font face="Courier New"&gt;HttpContext&lt;/font&gt; references which are time consuming and hard to mock out for testing purposes.&lt;/p&gt;  &lt;p&gt;In order to prevent this, I like to define an &lt;font face="Courier New"&gt;ICache&lt;/font&gt; interface that defines our contract for working with a cache.&lt;/p&gt;  &lt;p&gt;Something like this:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; ICache 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2: { 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3:    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey, DateTime expiry, T dataToAdd) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;; 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4:    T Get&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;; 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  5:    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey, DateTime expiry, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; dataToAdd); 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  6:    &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Get(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey); 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  7:    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvalidateCacheItem(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey); 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  8: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;With that, I can write a simple pass through &lt;font face="Courier New"&gt;CacheAdapter&lt;/font&gt; that implements this interface, but passes all the calls through to the ASP.NET Cache. Any components can then work with the &lt;font face="Courier New"&gt;CacheAdapter&lt;/font&gt; rather than the ASP.NET cache directly. This means we can mock it out easily by mocking the interface. Testing then becomes much easier and our code is loosely coupled. The &lt;font face="Courier New"&gt;CacheAdapter&lt;/font&gt; may look something like this:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; WebCacheAdapter : ICache
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  3:    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; System.Web.Caching.Cache _cache;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  4:    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; WebCacheAdapter()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  5:    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  6:       &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (System.Web.HttpContext.Current != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  7:          _cache = System.Web.HttpContext.Current.Cache;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  8:       &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  9:          &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentNullException(&amp;quot;&lt;span style="color: #8b0000"&gt;Not in a web context, unable to use the web cache.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 10:    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 11: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 12: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey, DateTime expiry, T dataToAdd) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 13: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 14:    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (dataToAdd != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 15:       _cache.Add(cacheKey, dataToAdd, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, expiry, Cache.NoSlidingExpiration, CacheItemPriority.Normal, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 16: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 17: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 18: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey, DateTime expiry, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; dataToAdd)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 19: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 20:    Add&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;(cacheKey, expiry, dataToAdd);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 21: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 22: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt; 23: &lt;span style="color: #008000"&gt;// rest of code omitted for brevity&lt;/span&gt;
&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;So that’s all well and good. Even though I am primarily a web guy, I often design and work with desktop applications which cannot use the ASP.NET cache. In addition, I may also want to use the awesome power of Windows AppFabric Cache for distributed caching. Furthermore, in a few scenarios it has been unclear whether distributed caching was an option due to infrastructure concerns. So I would have liked to use AppFabric caching, but may not be able to, and I would not have known this till later in the project. Finally, I do this kind of code a lot, and I did not want to write it for each scenario and have to specialise it for each project.&lt;/p&gt;

&lt;p&gt;It would be nice if I could have all the caching options I may need, already abstracted out for me, easily selectable via configuration, and utilise interfaces with dependency injection for easy testing and loosely coupled applications (what a mouthful).&lt;/p&gt;

&lt;p&gt;With that in mind, I have developed a simple caching architecture that I can introduce into all new projects and has the following features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Provides an &lt;font face="Courier New"&gt;ICache&lt;/font&gt; interface and associated cache adapter class through which all cache engines are accessed. This includes the .Net 4 &lt;font face="Courier New"&gt;MemoryCache&lt;/font&gt;, ASP.NET Web cache, and Windows AppFabric cache. &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;Provides an enhanced &lt;font face="Courier New"&gt;CacheProvider&lt;/font&gt; class (which implements &lt;font face="Courier New"&gt;ICacheProvider&lt;/font&gt;) that allows strongly typed cache access and a simple easy to use consistent API. &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;Allows selection of which cache engine to use via configuration. 
    &lt;ul&gt;
      &lt;li&gt;The currently supported cache mechanisms are 
        &lt;ul&gt;
          &lt;li&gt;Memory &lt;/li&gt;

          &lt;li&gt;Web &lt;/li&gt;

          &lt;li&gt;AppFabric &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;Fully supports dependency injection with everything already wired up. My current organisation standardises on Microsoft's Unity for Dependency Injection so that is what this library uses. 
    &lt;ul&gt;
      &lt;li&gt;&lt;font face="Courier New"&gt;Container.Resolve&amp;lt;ICacheProvider&amp;gt;();&lt;/font&gt; &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;is all you need to do to access the cache mechanism.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Provides simple logging diagnostics (again via dependency injection so its easy to change) so that you can track whats going on. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before I dive into the details, here is some example code to use this library and caching.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  1: var cacheProvider = AppServices.Resolve&amp;lt;ICacheProvider&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  3: Console.WriteLine(&amp;quot;&lt;span style="color: #8b0000"&gt;Getting Some Data.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  4: var data = cacheProvider.Get&amp;lt;SomeData&amp;gt;(&amp;quot;&lt;span style="color: #8b0000"&gt;cache-key&lt;/span&gt;&amp;quot;, DateTime.Now.AddSeconds(5), () =&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  5: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  6:    Console.WriteLine(&amp;quot;&lt;span style="color: #8b0000"&gt;... =&amp;gt; Adding data to the cache... &lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  7:    var someData = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SomeData() { SomeText = &amp;quot;&lt;span style="color: #8b0000"&gt;cache example1&lt;/span&gt;&amp;quot;, SomeNumber = 1 };
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  8:    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; someData;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  9: });
&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The preceding code sample first resolves our cache provider using the Unity container. Note that this is not an &lt;font face="Courier New"&gt;ICache&lt;/font&gt; instance (which we could also resolve and use directly), but rather a higher level &lt;font face="Courier New"&gt;ICacheProvider&lt;/font&gt; instance. This provides a more advanced and easy to use API for caching.&lt;/p&gt;

&lt;p&gt;Then we simply try and retrieve the item (of type &lt;font face="Courier New"&gt;SomeData&lt;/font&gt;) from the cache passing in a cache key, the expiry time of the cached data, and an anonymous function as the last argument.&lt;/p&gt;

&lt;p&gt;The anonymous function is only called if the data is not present in the cache. The return data of the anonymous function is placed into the cache using the cache key and expiry date/time, then returned to the caller.&lt;/p&gt;

&lt;p&gt;The library comes with some simple example code to allow you to get up and running very quickly. If you want to use it, you can download it from &lt;a href="http://theglavs.com/DownloadItem.aspx?FileID=67"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;For those who are interested in more detail, then read on.&lt;/p&gt;

&lt;p&gt;The design of the library is fairly simple.&lt;/p&gt;

&lt;p&gt;The solution itself consists of 4 projects as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/clip_image001_4FB3166F.png"&gt;&lt;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="clip_image001" border="0" alt="clip_image001" src="http://weblogs.asp.net/blogs/pglavich/clip_image001_thumb_25EF9B7C.png" width="244" height="165" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;Glav.CacheAdapter.Core&lt;/font&gt; contains all the necessary interfaces and an implementation of the &lt;font face="Courier New"&gt;MemoryCache&lt;/font&gt; (which implements &lt;font face="Courier New"&gt;ICache&lt;/font&gt;). There are multiple cache adapters (memory, web and AppFabric) which implement &lt;font face="Courier New"&gt;ICache&lt;/font&gt;. The &lt;font face="Courier New"&gt;ICache&lt;/font&gt; interface has basic Get/Remove methods to manipulate the cache. To facilitate a higher level API with easier usage and without introducing extra these methods into &lt;font face="Courier New"&gt;ICache&lt;/font&gt; (thus forcing each &lt;font face="Courier New"&gt;ICache&lt;/font&gt; adapter implementation to have to implement these methods), there is also a &lt;font face="Courier New"&gt;ICacheProvider&lt;/font&gt; interface which has the enhanced methods for retrieving items from the cache and automatically inserting them if the data items do not exist in the cache. Methods such as &lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 10px"&gt;  1: Get&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; cacheKey, DateTime expiryTime, GetDataToCacheDelete)&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Both &lt;font face="Courier New"&gt;Glav.CacheAdapter.Web&lt;/font&gt; and&lt;font face="Courier New"&gt; Glav.CacheAdapter.Distributed&lt;/font&gt; contain implementations of the &lt;font face="Courier New"&gt;ICache&lt;/font&gt; interface for ASP.NET and Windows AppFabric respectively. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/clip_image002_2FF416DA.png"&gt;&lt;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="clip_image002" border="0" alt="clip_image002" src="http://weblogs.asp.net/blogs/pglavich/clip_image002_thumb_5EF652B1.png" width="504" height="121" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Obviously, in order to use Windows AppFabric caching, you must have that installed on the machines that will utilise it. The library contains 2 core assemblies from Windows AppFabric that allow it to compile and reference the required functionality. If you enable AppFabric in the configuration of the library without it being installed and try to utilise caching, this will obviously fail.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/pglavich/clip_image003_34C6A4C9.png"&gt;&lt;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="clip_image003" border="0" alt="clip_image003" src="http://weblogs.asp.net/blogs/pglavich/clip_image003_thumb_719B269B.png" width="243" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, to glue all this together a project called the &lt;font face="Courier New"&gt;Glav.CacheAdapter.CacheBootstrap&lt;/font&gt; will register the correct cache implementation into the service container based on the supplied configuration. The .Net 4 &lt;font face="Courier New"&gt;MemoryCache&lt;/font&gt; is the default if no configuration or an unrecognised configuration is supplied.&lt;/p&gt;

&lt;p&gt;So that’s it. &lt;a href="http://theglavs.com/DownloadItem.aspx?FileID=67"&gt;Download it&lt;/a&gt; and give it a try if you want a nicely abstracted and pre-packaged cache solution. I would welcome any feedback.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7626328" width="1" height="1"&gt;</description></item><item><title>ASP.NET MVC 3 and Custom Extensions</title><link>http://weblogs.asp.net/pglavich/archive/2010/08/08/asp-net-mvc-3-and-custom-extensions.aspx</link><pubDate>Sun, 08 Aug 2010 04:03:24 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7581595</guid><dc:creator>Glav</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/pglavich/rsscomments.aspx?PostID=7581595</wfw:commentRss><comments>http://weblogs.asp.net/pglavich/archive/2010/08/08/asp-net-mvc-3-and-custom-extensions.aspx#comments</comments><description>&lt;p&gt;When playing with the latest &lt;a href="http://aspnet.codeplex.com/wikipage?title=Road%20Map&amp;amp;referringTitle=MVC" target="_blank"&gt;ASP.NET MVC 3 Preview 1&lt;/a&gt; bits, some people have mentioned their dislike of the .&lt;font size="2" face="Courier New"&gt;cshtml&lt;/font&gt; extension used for the “razor” view engine that comes with &lt;a href="http://aspnet.codeplex.com/wikipage?title=Road%20Map&amp;amp;referringTitle=MVC" target="_blank"&gt;ASP.NET MVC 3&lt;/a&gt; and also &lt;a href="http://www.asp.net/webmatrix" target="_blank"&gt;WebMatrix&lt;/a&gt;. Well there are a number of ways you can change this. For the purposes of learning and tinkering, I decided to try and register a new view engine using the new Dependency Injection support within ASP.NET MVC 3.&lt;/p&gt;  &lt;p&gt;So, in the &lt;font size="2" face="Courier New"&gt;Global.asax.cs&lt;/font&gt; file I did this:&lt;/p&gt;  &lt;pre&gt;protected void Application_Start()&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AreaRegistration.RegisterAllAreas();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; IUnityContainer container = new UnityContainer();&lt;br /&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; container.RegisterInstance&amp;lt;IControllerFactory&amp;gt;(new UnityControllerFactory(container));&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; container.RegisterType&amp;lt;IViewEngine, TestViewEngine&amp;gt;();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UnityMvcServiceLocator svcLocator = new UnityMvcServiceLocator(container);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; MvcServiceLocator.SetCurrent(svcLocator);&lt;br /&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; RegisterGlobalFilters(GlobalFilters.Filters);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; RegisterRoutes(RouteTable.Routes);&lt;br /&gt;}&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Note: Previously (and this options is still available), you would register your custom view engine by adding it to the existing Engines collections like so:&lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;&lt;em&gt;ViewEngines.Engines.Add(new TestViewEngine());&lt;br /&gt;&lt;/em&gt;&lt;/pre&gt;

&lt;p&gt;My Custom view engine looked like this:&lt;/p&gt;

&lt;pre&gt;public class TestViewEngine : VirtualPathProviderViewEngine&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public TestViewEngine()&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.AreaViewLocationFormats = new string[] { &amp;quot;~/Areas/{2}/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Areas/{2}/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.AreaMasterLocationFormats = new string[] { &amp;quot;~/Areas/{2}/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Areas/{2}/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.AreaPartialViewLocationFormats = new string[] { &amp;quot;~/Areas/{2}/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Areas/{2}/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.ViewLocationFormats = new string[] { &amp;quot;~/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.MasterLocationFormats = new string[] { &amp;quot;~/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; base.PartialViewLocationFormats = new string[] { &amp;quot;~/Views/{1}/{0}.glav&amp;quot;, &amp;quot;~/Views/Shared/{0}.glav&amp;quot; };&lt;br /&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return new CshtmlView(partialPath, &amp;quot;&amp;quot;);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return new CshtmlView(viewPath, masterPath);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;This view engine implementation looked for a view extension of ‘&lt;font size="2" face="Courier New"&gt;.glav&lt;/font&gt;’ and invokes the “razor” view to parse the document/page (&lt;em&gt;CshtmlView&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;ASP.NET MVC 3 will use the &lt;font size="2" face="Courier New"&gt;MvcServiceLocator&lt;/font&gt; that we have supplied, and call the ‘&lt;font size="2" face="Courier New"&gt;GetAllInstances’ &lt;/font&gt;method when determining what classes implement &lt;font size="2" face="Courier New"&gt;IViewEngine&lt;/font&gt; so that it can invoke the correct view engine.&lt;/p&gt;

&lt;p&gt;By default, ASP.NET MVC 3 has the &lt;font size="2" face="Courier New"&gt;System.Web.Mvc.WebFormViewEngine&lt;/font&gt; and the &lt;font size="2" face="Courier New"&gt;System.Web.Mvc.CshtmlViewEngine&lt;/font&gt; registered. We are adding a new custom view engine to the mix by registering it with the service locator that ASP.NET MVC uses ( &lt;font size="2" face="Courier New"&gt;MvcServiceLocator&lt;/font&gt; ). When ASP.NET MVC goes looking for a view engine it will use the &lt;font size="2" face="Courier New"&gt;MvcServiceLocator&lt;/font&gt; to get all instances of &lt;font size="2" face="Courier New"&gt;IViewEngine&lt;/font&gt; (via a call to ‘&lt;font size="2" face="Courier New"&gt;GetAllInstances’ &lt;/font&gt;) in order to try and satisfy the request to process/render a particular view.&lt;/p&gt;

&lt;p&gt;Now all this theory is good and well, and I thought it would work however it didn’t. One of the issues with Unity (and thats what I was basing my testing on since that was the example provided with ASP.NET MVC 3) is the the ' &lt;font size="2" face="Courier New"&gt;MvcServiceLocator.GetAllInstances&lt;/font&gt; ‘ method, calls the &lt;font size="2" face="Courier New"&gt;ResolveAll&lt;/font&gt; method of the &lt;font size="2" face="Courier New"&gt;UnityContainer&lt;/font&gt;. Now this *only* returns all instances if they have been registered by name, so I had to change one line of my code in the &lt;font size="2" face="Courier New"&gt;Global.asax.cs&lt;/font&gt; from:&lt;/p&gt;

&lt;pre&gt;container.RegisterType&amp;lt;IViewEngine, TestViewEngine&amp;gt;();&lt;/pre&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;pre&gt;container.RegisterType&amp;lt;IViewEngine, TestViewEngine&amp;gt;(&amp;quot;test&amp;quot;);&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;and it all worked and my new engine was invoked. Apparently this is known behaviour with Unity and may be changed in future versions, but for now, this is how it works.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: There are a few other ways of registering custom view engines and also associating file extensions with a particular view engine. This is just one way of doing it.&lt;/em&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7581595" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/pglavich/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/pglavich/archive/tags/MVC/default.aspx">MVC</category></item></channel></rss>
