<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0"><channel><title>OdeToCode by K. Scott Allen</title><description>OdeToCode by K. Scott Allen</description><copyright>(c) 2004 to 2013 OdeToCode LLC</copyright><managingEditor>scott@OdeToCode.com</managingEditor><generator>OdeToCode 2.0 with ASP.NET MVC 4</generator><image><url>http://odetocode.com/images/odetocode.jpg</url><title>OdeToCode by K. Scott Allen</title><link /></image><a10:link href="http://odetocode.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/OdeToCode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="odetocode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/17/using-system-js-in-mongodb-from-c.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/17/using-system-js-in-mongodb-from-c.aspx</link><author>scott@OdeTocode.com</author><title>Using system.js in MongoDB (From C#)</title><description>&lt;p&gt;The official &lt;a href="http://docs.mongodb.org/manual/tutorial/store-javascript-function-on-server/"&gt;MongoDB docs&lt;/a&gt; recommend that you &lt;em&gt;avoid&lt;/em&gt; storing scripts on the server, but there are scenarios where having reusable functions available on the server can be useful. Inside a MapReduce operation, for example.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll start with some JavaScript code encapsulating statistical calculations, and place the code in a file named mathStats.js:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;function() {

    var stdDev = function(numbers) {
        // ...  
    };

    var mode = function(numbers) {
        // ...
    };

    var mean = function(numbers) {
        // ...
    };

    return {
        stdDev: stdDev,
        mode: mode,
        mean: mean
    };

};
&lt;/pre&gt;
&lt;p&gt;Note the script must be a function. To use the methods inside, the function must live in the system.js collection. The following C# code can do this:&lt;/p&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false;"&gt;var sysJs = db.GetCollection("system.js");
var code = File.ReadAllText("pathTo\\mathStats.js");
var codeDocument = new BsonDocument("value", new BsonJavaScript(code));
codeDocument.Add(new BsonElement("_id", "mathStats"));
sysJs.Insert(codeDocument);

&lt;/pre&gt;
&lt;p&gt;It is important to insert the script as the&amp;nbsp; &lt;em&gt;value&lt;/em&gt; attribute of a document, and set the &lt;em&gt;_id&lt;/em&gt; of the document to a friendly string name and &lt;strong&gt;not&lt;/strong&gt; an ObjectID value. Failing to follow those two steps can lead to errors like &amp;ldquo;exception: name has to be a string&amp;rdquo; and &amp;ldquo;value has to be set&amp;rdquo; when you execute commands.&lt;/p&gt;
&lt;p&gt;Once the script is loaded, you can use the function from any map, reduce, or finalize function by invoking the function with its friendly _id name. For example:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;function(key, value){                      
    var stats = mathStats();
    value.stdDev = stats.stdDev(value.items);               
    return value;
}&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=9H6mmWfWpcY:TiqI69Mtxxs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Fri, 17 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/16/angularjs-abstractions-scope.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/16/angularjs-abstractions-scope.aspx</link><author>scott@OdeTocode.com</author><title>AngularJS Abstractions: Scope</title><description>&lt;p&gt;Continuing from the &lt;a href="http://odetocode.com/blogs/scott/archive/2013/05/13/angularjs-abstractions-controllers.aspx"&gt;controllers&lt;/a&gt; post, the parameter to the controller function is named $scope.&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;var AboutController = function($scope) {

    // ...    

};
&lt;/pre&gt;
&lt;p&gt;The name $scope is important since it allows the AngularJS dependency injector to know what type of object you are asking for, in this case an &lt;strong&gt;object that will contain the view model&lt;/strong&gt;. Any plain old JavaScript you attach to $scope (properties, functions, objects, arrays) is eligible to use from the expressions inside the view.&lt;/p&gt;
&lt;p&gt;In the last post our model was relatively &amp;ldquo;flat&amp;rdquo; in the sense that properties and functions were added directly to $scope:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;$scope.rabbitCount = 2;

$scope.increase = function() {
    $scope.rabbitCount *= $scope.rabbitCount;
};
&lt;/pre&gt;
&lt;p&gt;This allowed us to use rabbitCount and increase() in the markup that was inside the view scope (the div) of the AboutController:&lt;/p&gt;
&lt;pre class="brush: xml; gutter: false; toolbar: false;"&gt;&amp;lt;div data-ng-controller="AboutController"&amp;gt;

    &amp;lt;div&amp;gt;Number of rabbits in the yard: {{rabbitCount}}&amp;lt;/div&amp;gt;

    &amp;lt;button ng-click="increase()"&amp;gt;More rabbits&amp;lt;/button&amp;gt;
    
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&lt;img style="float: right; margin: 0px 0px 0px 10px; display: inline;" src="http://odetocode.com/images2/Windows-Live-Writer/Angular-Abstractions-The-Application_F661/image_3.png" alt="" align="right" /&gt;&lt;/p&gt;
&lt;p&gt;You can think of $scope as the execution context for the expressions in the view. Saying ng-click=&amp;rdquo;increase&amp;rdquo; results in a call to $scope.increase. The only thing tricky to understand about $scope is that having a controller inside a controller, or a controller inside an application (which you&amp;rsquo;ll always have), will result in nested $scopes, and a nested $scope will &lt;a href="http://msdn.microsoft.com/en-us/magazine/ff852808.aspx"&gt;&lt;strong&gt;prototypally inherit&lt;/strong&gt;&lt;/a&gt; from it&amp;rsquo;s parent scope by default. This is why $scope is injected by angularJS &amp;ndash; the framework sets up the prototype chain before giving your controller the $scope object to use as a model.&lt;/p&gt;
&lt;p&gt;Inheritance means a view has access to it&amp;rsquo;s own scope as well as any inherited scope. In the following example, the view inside the ChildController markup can use an expression like {{rabbitCount}}, and this expression will read the rabbitCount property of AboutController&amp;rsquo;s scope ($scope.rabbitCount will follow the prototype chain).&lt;/p&gt;
&lt;pre class="brush: xml; gutter: false; toolbar: false;"&gt;&amp;lt;div data-ng-controller="AboutController"&amp;gt;    

    &amp;lt;div&amp;gt;Number of rabbits in the yard: {{rabbitCount}}&amp;lt;/div&amp;gt;
    
    &amp;lt;div data-ng-controller="ChildController"&amp;gt;
        Number of rabbits in the yard: {{rabbitCount}}
        Number of squirrels in the yard: {{squirrelCount}}
    &amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The one place to be careful with the inherited scope is with 2 way data binding. The way JavaScript prototypes work is that &lt;strong&gt;writing&lt;/strong&gt; to the rabbitCount property of the ChildController $scope will add a rabbitCount property to the ChildController $scope and effectively hide the parent property. $scope.rabbitCount no longer needs to follow the prototype chain to find a value. More details and pictures on this scenario in &amp;ldquo;&lt;a href="https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance"&gt;The Nuances of Scope Prototypal Inheritance&lt;/a&gt;&amp;rdquo;.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=rOKHOvFO_Rc:GGUXUQ6obwk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Thu, 16 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/15/where-is-net-headed.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/15/where-is-net-headed.aspx</link><author>scott@OdeTocode.com</author><title>Where Is .NET Headed?</title><description>&lt;p&gt;I watched the &lt;a href="http://www.youtube.com/watch?v=w6t0hP5wgPQ"&gt;dotNetConf .NET Open Source Panel&lt;/a&gt; last week. It was a bit disappointing to hear defeatism in the voices of OSS project leaders, because .NET&amp;rsquo;s future appears to rely &lt;em&gt;entirely&lt;/em&gt; on the success of open source software for .NET. Here are a couple reasons:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;The success of Windows Azure&lt;/strong&gt;. Azure is now an amazing cloud platform for developers and is getting better every few weeks. Azure is also a business success with annual revenue topping &lt;a href="http://www.bloomberg.com/news/2013-04-29/microsoft-azure-sales-top-1-billion-challenging-amazon.html"&gt;$1 billion&lt;/a&gt;. That&amp;rsquo;s $1 billion with only a 20% share of a $6 billion dollar market &amp;ndash; a market that is expected to grow to $30 billion in 4 years. As Azure continues to pick up market share it is not completely unthinkable to see it post a 15+ billion dollar year in 2018, which is getting into the same double-digit-billion-dollar-revenue neighborhood as Windows itself.&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://www.windowsazure.com/en-us/documentation/"&gt;documentation&lt;/a&gt; page for Azure makes it clear where the growth will come from:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.windowsazure.com/en-us/documentation/"&gt;&lt;img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="image" src="http://odetocode.com/images2/Windows-Live-Writer/dotNetConf-Open-Source-Panel_FB1C/image_3.png" alt="Azure Strategy" width="644" height="221" border="0" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To paraphrase the above graphic, Microsoft doesn&amp;rsquo;t need legions of developers building frameworks and tools for Windows developers when they can have legions of programmers building tools and a cloud platform for &lt;em&gt;all&lt;/em&gt; developers. Hadoop, Redis, NodeJS, RoR, Django, PHP, and the list goes on. Even if it doesn&amp;rsquo;t run on Windows, you can always spin up a ready made Azure virtual machine image with Ubuntu, CentOS, or SUSE.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t think Azure needs a successful server-side .NET framework to be a success itself.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;The Direction of Windows 8&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I still feel Window 8 carpet bombed .NET developers. There was secrecy and hearsay followed by the death of one XAML platform and the arrival of yet another slightly different XAML platform. People running a business based on desktop technology don&amp;rsquo;t know where to place their bets and the Windows division has always appeared hostile to the CLR. I&amp;rsquo;m not sure what this year&amp;rsquo;s Build and Windows Blue will bring, but I can only hope it offers some direction for businesses who build desktop business applications with managed code.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t think Windows wants to see a successful client-side .NET framework.&lt;/p&gt;
&lt;h3&gt;Where Are We?&lt;/h3&gt;
&lt;p&gt;It feels as if Microsoft has shifted focus away from .NET, and with the focus goes resources and innovation. Much of the CLR and it&amp;rsquo;s associated assemblies and languages appear to be entering maintenance or refinement mode instead of advancing in new directions. Anyone building software on Microsoft&amp;rsquo;s .NET platform should see this as cause for concern.&lt;/p&gt;
&lt;p&gt;Except &amp;hellip;&lt;/p&gt;
&lt;p&gt;The circle of&amp;nbsp; software loosely surrounding .NET is exploding. There are &lt;a href="http://odetocode.com/blogs/scott/archive/2013/02/12/you-want-to-build-web-software-with-c.aspx"&gt;more server side framework choices for C# developers&lt;/a&gt; than ever before, and client side web programming has advanced rapidly over the last few years with open source projects like AngularJS, Backbone, Ember, and Meteor. Document databases like MongoDB and RavenDB and key-value stores like Redis are all available to managed code, and products like &lt;a href="http://xamarin.com/studio"&gt;Xamarin&lt;/a&gt; are pushing C# and mono to new platforms. What I&amp;rsquo;ve listed is a small sampling of what is happening and it is all pretty amazing when you sit back and look at the bigger picture.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Plus, if you already build solutions with ASP.NET MVC, Web Pages, the WebAPI, or the Entity Framework, you are already building software &lt;a href="http://www.asp.net/open-source" target="_blank"&gt;on top of open source projects&lt;/a&gt; that rely on other open source projects from the community.&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;What To Do?&lt;/h3&gt;
&lt;p&gt;If your business or company still relies solely on components delivered to developers through an MSDN subscription, then it is past time to start looking beyond what Microsoft offers for .NET development so you won&amp;rsquo;t be left behind in 5 years. Embrace and support open source.&lt;/p&gt;
&lt;p&gt;At least, that&amp;rsquo;s how I see things.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=gCGH2IguijY:nhAe0IaNFJc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 15 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/13/angularjs-abstractions-controllers.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/13/angularjs-abstractions-controllers.aspx</link><author>scott@OdeTocode.com</author><title>AngularJS Abstractions: Controllers</title><description>&lt;p&gt;&lt;img style="float: right; margin: 0px 0px 0px 10px; display: inline" align="right" src="http://odetocode.com/images2/Windows-Live-Writer/Angular-Abstractions-The-Application_F661/image_3.png"&gt;In MVC web programming server side controllers are responsible for reacting to an external stimulus (an HTTP request), and then building a model and possibly rendering a view in response to the stimulus. In a client app with AngularJS, the controller has an easier job. &lt;/p&gt; &lt;p&gt;AngularJS is officially a &lt;a href="https://plus.google.com/+AngularJS/posts/aZNVhj355G2"&gt;Model-View-Whatever&lt;/a&gt; framework, meaning there is quite a bit of flexibility in the architecture of an application. But, if you follow the typical conventions, a controller is simply a function the framework will call at the appropriate time. It’s the controller’s responsibility to put together a model by any means possible, and then the controller function is complete.&amp;nbsp; &lt;/p&gt; &lt;p&gt;One notable difference between a controller in server side world of Rails or ASP.NET MVC&amp;nbsp; and a controller with AngularJS is the view selection. Controllers and views are generally bound together on the client using directives (ng-controller) or in routing rules (a topic for a future post). &lt;/p&gt; &lt;p&gt;As an example, the following html is setting up the AboutController to manage the primary div element in the document. The primary div also contains some data binding expressions. &lt;/p&gt;&lt;pre class="brush: xml; gutter: false; toolbar: false;"&gt;&amp;lt;body data-ng-app="patientApp"&amp;gt;
                          
    &amp;lt;div data-ng-controller="AboutController"&amp;gt;
        &amp;lt;h3&amp;gt;{{message}}&amp;lt;/h3&amp;gt;
        &amp;lt;div&amp;gt;Number of rabbits in the yard: {{rabbitCount}}&amp;lt;/div&amp;gt;

        &amp;lt;button ng-click="increase()"&amp;gt;More rabbits&amp;lt;/button&amp;gt;
        &amp;lt;button ng-click="decrease()"&amp;gt;Less rabbits&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script src="libs/angular.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="scripts/myScript.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/pre&gt;
&lt;p&gt;When AngularJS takes control of the DOM it will see the ng-controller directive and go off searching for an AboutController. Here is one way to write the controller:&lt;/p&gt;&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function () {
    
    var AboutController = function($scope) {

        $scope.message = "Hello from the AboutController!";
        
        $scope.rabbitCount = 2;
        
        $scope.increase = function() {
            $scope.rabbitCount *= $scope.rabbitCount;
        };
        
        $scope.decrease = function() {
            $scope.rabbitCount -= 1;
        };
    };
    
    // Describe dependencies for the injector
    // in a minifier friendly way.
    AboutController.$inject = ["$scope"];

    // Register the controller as part of a module.
    // The patientApp module will need to take a 
    // dependency on patientApp.Controllers.
    angular.module("patientApp.Controllers")
           .controller("AboutController", AboutController);
    
}());
&lt;/pre&gt;
&lt;p&gt;Once AngularJS finds the controller, the framework invokes the function and injects any dependencies the controller requires. In this case the controller is simple and only requires a $scope dependency. We’ll talk about $scope in a future post, for now you can think of $scope as the model object you need to enhance for the application to work. The HTML contains data binding expressions like {{message}} and ng-click directives that will send the framework looking for functions to invoke named &lt;em&gt;increase&lt;/em&gt; and &lt;em&gt;decrease&lt;/em&gt;. These are all attributes the controller needs to provide on the $scope object. &lt;/p&gt;


&lt;p&gt;In many respects the $scope object feels like a view model in an MVVM environment like Silverlight. The data binding expressions push and pull data into properties of the view model. The command type bindings, like &lt;em&gt;ng-click=increase()&lt;/em&gt;, invoke methods on the view model. And the view model (a.k.a $scope object) behaves in true view model like fashion in the sense that it knows &lt;em&gt;nothing&lt;/em&gt; about the view or the DOM. The view model only needs to change values internally and data binding takes care of the rest. Clean and testable. &lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=sY-aprxd22g:NiJbJ2h1GsM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 13 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/10/trying-out-redis-via-nuget.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/10/trying-out-redis-via-nuget.aspx</link><author>scott@OdeTocode.com</author><title>Trying Out Redis via NuGet</title><description>&lt;p&gt;From the &lt;a href="http://redis.io/"&gt;Redis&lt;/a&gt; home page:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain &lt;a href="http://redis.io/topics/data-types#strings"&gt;strings&lt;/a&gt;, &lt;a href="http://redis.io/topics/data-types#hashes"&gt;hashes&lt;/a&gt;, &lt;a href="http://redis.io/topics/data-types#lists"&gt;lists&lt;/a&gt;, &lt;a href="http://redis.io/topics/data-types#sets"&gt;sets&lt;/a&gt; and &lt;a href="http://redis.io/topics/data-types#sorted-sets"&gt;sorted sets&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Redis is also fast. Incredibly fast. Mind-numbing fast.&lt;/p&gt;
&lt;p&gt;For more information, try the Redis &lt;a href="http://redis.io/documentation"&gt;docs&lt;/a&gt; or &amp;ldquo;&lt;a href="http://openmymind.net/redis.pdf"&gt;The Little Redis Book&lt;/a&gt;&amp;rdquo; by Karl&amp;nbsp; Seguin.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/MSOpenTech"&gt;MSOpenTech&lt;/a&gt; just released a NuGet package of their Windows port to make it easy to download Redis and try the server from the command line. Combine this package with the &lt;a href="https://github.com/ServiceStack/ServiceStack.Redis"&gt;ServiceStack.Redis&lt;/a&gt; package and it easy to be up and running quickly.&lt;/p&gt;
&lt;pre class="brush: plain; gutter: false; toolbar: false;"&gt;install-package redis-64
install-package servicestack.redis
&lt;/pre&gt;
&lt;p&gt;The redis-64 package (for 64 bit systems) doesn&amp;rsquo;t add assembly references to a project, but does drop the Redis server executable in the packages\Redis-64.{version}\tools directory of the solution. Opening a command window and running redis-server.exe will launch the server with the default settings.&lt;/p&gt;
&lt;p&gt;Here is a quick C# program to store and retrieve an object using the ServiceStack client:&lt;/p&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false;"&gt;static void Main(string[] args)
{
    var client = new RedisClient("localhost");
    var patientClient = client.As&amp;lt;Patient&amp;gt;();

    var patient = new Patient
        {
            Name = "Scott", 
            Codes = new List&amp;lt;string&amp;gt; {"1.1", "2.2"}
        };
    patient.Id = patientClient.GetNextSequence();
    patientClient.Store(patient);

    var retrievedPatient = patientClient.GetById(patient.Id);
    Console.WriteLine("{0}:{1}", retrievedPatient.Id, retrievedPatient.Name);

}
&lt;/pre&gt;
&lt;p&gt;Once the program runs, you can also go to the command line client in the tools directory (redis-cli.exe), and verify the data stored inside of Redis. Here is a shot of the cli client and server running:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://odetocode.com/images2/Windows-Live-Writer/Trying-Out-New-Redis-NuGet-Packages_13462/redis_2.png"&gt;&lt;img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="" src="http://odetocode.com/images2/Windows-Live-Writer/Trying-Out-New-Redis-NuGet-Packages_13462/redis_thumb.png" alt="Redis running from NuGet" width="640" height="440" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=yNx9GWvYcLw:iF9A7CcZA8A:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Fri, 10 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/07/angularjs-abstractions-organizing-modules.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/07/angularjs-abstractions-organizing-modules.aspx</link><author>scott@OdeTocode.com</author><title>AngularJS Abstractions: Organizing Modules</title><description>&lt;p&gt;&lt;img style="background-image: none; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 10px; display: inline; padding-right: 0px; border: 0px;" src="http://odetocode.com/images2/Windows-Live-Writer/Angular-Abstractions-The-Application_F661/image_3.png" alt="image" align="right" border="0" /&gt;Now that we know a bit about &lt;a href="http://odetocode.com/blogs/scott/archive/2013/05/01/angularjs-abstractions-modules.aspx"&gt;how modules work at an API level&lt;/a&gt;, we can look at questions that will be asked more than once in the lifetime of a project, like when to create a module, how many modules to create, and how to organize source code files for a module.&lt;/p&gt;
&lt;p&gt;One thing to recognize early on is how much flexibility is available. Although the term "module" sounds like the JavaScript module design pattern (a single function inside a single file), there is nothing about an AngularJS module that requires all the code for a module to exist in a single file, or in a single function. Your code can use multiple JavaScript modules to add features to a single AngularJS module.&lt;/p&gt;
&lt;p&gt;The code below is creating an alerter service to add to the patientApp.Services module, and could be one of many such pieces of code scattered across various files.&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function () {
    var alerter = function () {
        // ...
    };

    angular.module("patientApp.Services")           
           .factory("alerter", alerter);
}());
&lt;/pre&gt;
&lt;p&gt;Given this amount of flexibility, there are no real limitations on the number of modules and files you create.&lt;/p&gt;
&lt;p&gt;Use an approach that causes the least amount of friction for you and the team. Factors to evaluate include the test and deployment strategy and the reusability of a module across multiple apps. Managing the dependencies of a large number of modules produces friction. Building large monolithic modules can also produce friction. Somewhere in between is a sweet spot.&lt;/p&gt;
&lt;h3&gt;Reference Material&lt;/h3&gt;
&lt;p&gt;There is already some good material out there on organizing file and modules.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/angular/angular-seed/tree/master/app/js"&gt;Angular Seed&lt;/a&gt; project recommends creating one module for controllers, one for directives, one for filters, and one for services. I'm not a fan of choosing this approach as a default.&lt;/p&gt;
&lt;p&gt;Brian Ford has a post on &lt;a href="http://briantford.com/blog/huuuuuge-angular-apps.html"&gt;Building Huuuuuuge Apps with AngularJS&lt;/a&gt;. Brian suggestion: "Each file should have one "thing" in it, where a "thing" is a controller, directive, filter, or service".&lt;/p&gt;
&lt;p&gt;Cliff Meyers also believes in one thing per file in his post "&lt;a href="http://cliffmeyers.com/blog/2013/4/21/code-organization-angularjs-javascript"&gt;Code Organization in Large AngularJS and JavaScript applications&lt;/a&gt;". I like that Cliff uses a dedicated folder for models instead of throwing in models with services or controllers.&lt;/p&gt;
&lt;p&gt;Finally, Jim Lavin has "&lt;a href="http://codingsmackdown.tv/blog/2013/04/19/angularjs-modules-for-great-justice/"&gt;AngularJS Modules for Great Justice&lt;/a&gt;" and talks about the concepts of "package by layer" versus "package by feature".&lt;/p&gt;
&lt;p&gt;One scenario I haven't found addressed very well is the scenario where multiple apps exist in the same greater web application and require some shared code on the client. I'll try to blog about this one in the future, but we'll visit some of the other AngularJS abstractions first.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=sNIR4wEtXVE:zdV1nQW9TPk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Tue, 07 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/06/what-ive-been-doing.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/06/what-ive-been-doing.aspx</link><author>scott@OdeTocode.com</author><title>What I've Been Doing</title><description>&lt;p&gt;People ask me what I do on a a regular basis. For this and various other reasons I'll shed some light on the current situation.&lt;/p&gt;
&lt;p&gt;&lt;img style="float: right; margin: 0px 0px 0px 10px; display: inline;" title="" src="http://medisolv.com/images/logo.png" alt="medisolv" width="100" height="47" align="right" /&gt;1.&lt;a href="http://medisolv.com/"&gt;&lt;strong&gt;Medisolv&lt;/strong&gt;&lt;/a&gt; is a company I've worked with in various roles for the last 10+ years. I'm now CTO, but still work with various product teams and commit production code as often as possible, which is by far finest part of the job. We will be &lt;a href="http://medisolv.com/careers.php"&gt;&lt;strong&gt;hiring&lt;/strong&gt;&lt;/a&gt; more software developers in the near future, so keep an eye out if you are interested.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://odetocode.com/images2/Windows-Live-Writer/What-I-Do_1028F/naval_5.jpg"&gt;&lt;img style="background-image: none; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 10px; display: inline; padding-right: 0px; border: 0px;" title="" src="http://odetocode.com/images2/Windows-Live-Writer/What-I-Do_1028F/naval_thumb_1.jpg" alt="Battle Of Valcour With Pluralsight Crystal" width="244" height="139" align="right" border="0" /&gt;&lt;/a&gt;2. &lt;a href="http://pluralsight.com/training"&gt;&lt;strong&gt;Pluralsight&lt;/strong&gt;&lt;/a&gt; is where I make glorious training videos. I'm currently working on a couple different courses and plan to finish "Learning To Program" in the next couple weeks. Making videos for Pluralsight is fun. Over the years I've collected 8 crystal microphones from Pluralsight as an award for making a Top 10 course. Occasionally I arrange them on the floor to recreate great naval battles from the 18th century. The photo to the right is the Battle of Valcour Island. You can see General Carleton advancing British warships towards the American's &lt;em&gt;Congress&lt;/em&gt; and &lt;em&gt;Royal Savage.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;3. &lt;strong&gt;OdeToCode LLC&lt;/strong&gt; is the company I own and operate for consulting services, but I've scaled back operations to simplify life and I am currently not taking on new work.&lt;/p&gt;
&lt;p&gt;4. &lt;strong&gt;Workshops, Classes, and Conferences&lt;/strong&gt; allow me to occasionally get out and see the world. I enjoy the classes I teach for &lt;a href="http://www.developerfocus.com/"&gt;DeveloperFocus&lt;/a&gt; and &lt;a href="http://www.programutvikling.no/"&gt;ProgramUtvikling&lt;/a&gt; and plan to update and revise my current curriculum to include topics like AngularJS and web service design with WebAPI. Conferences are fun, but also stressful and time consuming, so I'm cutting back. I will be at &lt;a href="http://devsum.se/"&gt;DevSum&lt;/a&gt;, &lt;a href="http://www.ndcoslo.com/"&gt;NDC&lt;/a&gt;, and the fall &lt;a href="http://devintersection.com/"&gt;DevIntersection&lt;/a&gt; this year.&lt;/p&gt;
&lt;p&gt;And now, back to work&amp;hellip;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=TMEad3SIsuk:BytaJ4GSIFc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 06 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/05/01/angularjs-abstractions-modules.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/05/01/angularjs-abstractions-modules.aspx</link><author>scott@OdeTocode.com</author><title>AngularJS Abstractions: Modules</title><description>&lt;p&gt;Continuing from the &lt;a href="http://odetocode.com/blogs/scott/archive/2013/04/30/angular-abstractions-the-application.aspx"&gt;last post&lt;/a&gt;, a module in AngularJS is a place where you can collect and organize components like controllers, services, directives, and filters. We'll talk about the "when &amp;amp; why" of creating a module in a later post. This post will focus on the API to create a module, and get a reference to an existing module. Stimulating topic, eh?&lt;/p&gt;
&lt;p&gt;The proper way to create a module is to use the angular.module method passing at least the module name, and an array naming all the dependencies of the module&amp;nbsp; (or an empty array if there are no dependencies).&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;angular.module("patientApp.Services", []);
angular.module("patientApp.Controllers", []);   
angular.module("patientApp", ["patientApp.Services",
                              "patientApp.Controllers"]);
&lt;/pre&gt;
&lt;p&gt;The above code actually creates three modules &amp;ndash; patientApp.Services, patientApp.Controllers, and a patientApp module that depends on the previous two modules. I like to have all this code centralized in one place for easy management.&lt;/p&gt;
&lt;p&gt;The following code defines the three modules, then comes back and adds a "run block" to the patientApp module (a run block is a piece of code that Angular will invoke once the module is assembled and configured).&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function () {
    "use strict";

    angular.module("patientApp.Services", []);
    angular.module("patientApp.Controllers", []);   
    angular.module("patientApp", ["patientApp.Services",
                                  "patientApp.Controllers"]);

    var app = angular.module("patientApp");
    app.run(["$rootScope", function ($rootScope) {
        $rootScope.patientAppVersion = "0.0.0.1";
    }]);
    
}());&lt;/pre&gt;
&lt;p&gt;Note the call to angular.module("patientApp") does not pass a second parameter with required module names, doing so would recreate the module and destroy anything already registered inside. Calling angular.module with just the module name will give you back a reference to an existing module so you can continue adding run blocks, services, directives, and other components into the module.&lt;/p&gt;
&lt;p&gt;Somewhere else in the same file, or in a separate file, another block of JavaScript code might add an "alerter" service to the 'patientApp.Services' module (I know we haven't talked about services yet, but we will, and the short summary is that a service can carry out a specific task, like communicate over the network, and a service typically contains code you want isolated for testability or to obey the single responsibility principle).&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function () {
    var alerter = function () {
        return {
            alert: function (message) {
                // ... do something alerty
            }
        };
    };

    angular.module("patientApp.Services")           
           .factory("alerter", alerter);
}());
&lt;/pre&gt;
&lt;p&gt;The API and terminology around services in Angular is unfortunately confusing and sometimes misleading, but we'll talk about that, too. For now, think of the factory method as "registering a service" in the module. &lt;strong&gt;The factory method is not providing a factory for the module itself,&lt;/strong&gt; as the name might imply&lt;strong&gt;.&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yet another hunk of script from a different file can add a logger service to the same module.&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function() {

    var logger = function() {
      
        var log = function(message) {
            // .. do something loggy
        };

        return {
            log: log,            
        };
    };

    angular.module("patientApp.Services")
           .factory("logger", logger);           

}());
&lt;/pre&gt;
&lt;p&gt;Of course, that could have all been combined together, if you so desire:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function() {
    "use strict";

    var alerter = function () {
        //...
    };

    var logger = function() {
        //...
    };

    angular.module("patientApp.Services")
           .factory("alerter", alerter)
           .factory("logger", logger);           

}());
&lt;/pre&gt;
&lt;p&gt;Now that we understand a bit about how to create modules, we'll talk about the "when and why" in a future post.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=69RSgAmRXsE:sFyrB-YAFy8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 01 May 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/04/30/angular-abstractions-the-application.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/04/30/angular-abstractions-the-application.aspx</link><author>scott@OdeTocode.com</author><title>Angular Abstractions: The Application</title><description>&lt;p&gt;&lt;img style="float: right; margin: 0px 0px 0px 10px; display: inline;" title="image" src="http://odetocode.com/images2/Windows-Live-Writer/Angular-Abstractions-The-Application_F661/image_3.png" alt="image" width="120" height="120" align="right" /&gt;One of the nice features of AngularJS is how the framework comes with a complete set of abstractions and features for building complex client pages from loosely structured and maintainable pieces of code. There are controllers, services, directives, data binding, and other pieces we'll continue looking at in future posts.&lt;/p&gt;
&lt;p&gt;Angular also includes the concept of an application, which is the topic for this post.&lt;/p&gt;
&lt;p&gt;An application is just an Angular module, which leads to a chicken and egg problem, since we haven't talked about modules, yet, but for now you can think of a module as an abstraction for packaging up related pieces of code.&lt;/p&gt;
&lt;p&gt;For example, with Angular you can place all your controllers into a one module and all your services into a second module, or put the controllers and services all inside a single module. How many modules you define is entirely up to you and the needs of the project. Modules exist as containers that can provide configuration information, runtime dependencies, and other infrastructure support for their residents.&lt;/p&gt;
&lt;p&gt;There are usually two features of the application module that make it "the application".&lt;/p&gt;
&lt;p&gt;First is that the application module should know about all the other modules in the software, while those other modules might not know about each other or the application. Thus, the application module is the perfect place to bootstrap and glue together all the other components.&lt;/p&gt;
&lt;p&gt;Secondly, the application module is the one identified by the ngApp directive. You can place this directive in the DOM using ng-app or data-ng-app attributes, as shown below in the simplest possible AnguarJS + HTML 5 page.&lt;/p&gt;
&lt;pre class="brush: xml; gutter: false; toolbar: false;"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;   
        &amp;lt;title&amp;gt;Patient Data&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
&amp;lt;body data-ng-app="PatientApp"&amp;gt;
    &amp;lt;div&amp;gt;
        {{ patientAppVersion }}            
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="libs/angular.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="&amp;hellip; my scripts &amp;hellip;"&amp;gt;&amp;lt;/script&amp;gt;    
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;You can have multiple applications inside a single page, but typically there will only be a single application and the ng-app directive will appear on the document's body element. After Angular loads and processes the HTML in the DOM, it will go looking for the "patientApp" module, so the following code is required:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function () {
    "use strict";

    var app = angular.module("PatientApp", []);

    app.run(function ($rootScope) {
        $rootScope.patientAppVersion = "0.0.0.1";
    });

}());
&lt;/pre&gt;
&lt;p&gt;angular.module is the API to use for creating and configuring a module. The first parameter is the name of the module, the 2nd parameter describes the other modules this module depends on (there currently are none).&lt;/p&gt;
&lt;p&gt;The .run method will give Angular a function to execute after all the modules are loaded and the dependencies are resolved. In this sample, we'll add a property to $rootScope, which is the scope in use in the previous HTML (since we have no controllers yet). The magic of {{ data binding }} allows the web page to display the text "0.0.0.1".&lt;/p&gt;
&lt;p&gt;You can reference the patientApp module from other JavaScript files using angular.module. The following code block could live in a separate .js file, and demonstrates how different pieces of code could be tied together to execute during the application bootstrap phase:&lt;/p&gt;
&lt;pre class="brush: js; gutter: false; toolbar: false;"&gt;(function() {
    "use strict";

    var app = angular.module("PatientApp");
  
    app.run(["$rootScope", function($rootScope) {
        $rootScope.patientAppGreeting = "Hello!";
    }]);  

}());
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the call to angular.module does not have a 2nd parameter (the list of dependencies) in this second block. The dependencies param should only appear once for a given module. &lt;strong&gt;Passing the dependencies parameter again will wipe out the module definition and start over&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Also note the second code block uses a style that is safe for minification because it passes $rootScope (a well known name to Angular) in an array along with the function to invoke during the run phase. Anytime you define a function where Angular will inject dependencies you are given the option of passing the function as the last element in an array that gives Angular the well known names of the dependencies required as arguments. We'll see more examples of this style as we move forward.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=5HGNyKdS56c:KYpvR7QxqsM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Tue, 30 Apr 2013 09:12:00 Z</pubDate></item><item><guid isPermaLink="true">http://odetocode.com/blogs/scott/archive/2013/04/29/the-tablet-show-82.aspx</guid><link>http://odetocode.com/blogs/scott/archive/2013/04/29/the-tablet-show-82.aspx</link><author>scott@OdeTocode.com</author><title>The Tablet Show #82</title><description>&lt;p&gt;The one where I talk to Carl and Richard about everything from AngularJS, Durandal, and Glimpse to relationships and finding your true love. &lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thetabletshow.com/default.aspx?showNum=82" target="_blank"&gt;&lt;strong&gt;Listen or download the show here&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thetabletshow.com/default.aspx?showNum=82"&gt;&lt;img title="" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Tablet Show #82" src="http://odetocode.com/images2/Windows-Live-Writer/1df7753d8393_70D3/leds2_6.jpg" width="640" height="108"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/OdeToCode?a=D4-Y7kynLyA:6AwCsVtpx5I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/OdeToCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 29 Apr 2013 09:12:00 Z</pubDate></item></channel></rss>
