Friday, October 24, 2014

Book Review: Learning AngularJS for .NET Developers

The subtitle of Alex Pop's Learning AngularJS for .NET Developers (Packt Publishing) is "Build single-page web applications using frameworks that help you work efficiently and deliver great results." Learning AngularJS for .NET Developers consists of approximately 175 substantive pages divided into 6 chapters. This blog post is my review of Learning AngularJS for .NET Developers.


The "Preface" of Learning AngularJS for .NET Developers describes how web development has changed with focus on single-page applications behaving more like desktop applications and using approaches such as responsive web design and progressive enhancement.

The Preface also describes the objective of the Learning AngularJS for .NET Developers and the experience readers of the book should have before reading it:

The main focus of this book is on how to rapidly prototype and build modern web applications with AngularJS in the context of .NET development tools and frameworks. The book assumes the reader has already built websites, web applications, or web services using Microsoft technologies such as ASP.NET, ASP.NET MVC, Silverlight, or WCF and knows the fundamentals of HTML5, CSS3, JavaScript, jQuery, and ASP.NET MVC.

The "Who this book is for" section of the Preface reaffirms its intended audience: "The book is targeted at .NET developers who have already built web applications or web services and have a fundamental knowledge of HTML, JavaScript, and CSS. As is the case with other Packt Publishing books I have reviewed, the Preface of Learning AngularJS for .NET Developers provides short descriptions of each of the book's six chapters.

The final significant observation from Learning AngularJS for .NET Developers's Preface that is important to highlight here comes from its "What you need for this book" section. That section states that Visual Studio 2013 Professional is recommended, but that Visual Studio 2013 Express for Web is sufficient. Node.js, Node.js Tools for Visual Studio, and JDK 7 are recommended for testing. Later in the book, the author also recommends use of Google Chrome web browser with the AngularJS Batarang extension.

Chapter 1: Introducing AngularJS

The initial chapter of Learning AngularJS for .NET Developers is dedicated to AngularJS. The chapter includes a reference to the AngularJS 1.2.15 Documentation and to the AngularJS 1.2.15 API Documentation because a single chapter cannot cover all the details of AngularJS. The chapter then uses examples to introduce AngularJS concepts.

The first examples of Chapter 1 demonstrate fundamental characteristics of an AngularJS application by comparing a single example written in AngularJS to the same example implemented with jQuery and JavaScript. This comparison and the accompanying text are a nice method for introducing AngularJS, how it is different, and highlighting some of its advantages. The text description associated with the first comparison-oriented example introduces significant AngularJS concepts such as directives, expressions, and scopes.

Learning AngularJS for .NET Developers's first chapter includes sections on AngularJS architecture and the structure of an AngularJS application. The latter part includes discussion of AngularJS modules. The section on "JavaScript patterns and practices used in AngularJS applications" includes some nice explanations of JavaScript scope and hoisting issues and how these are often dealt with in AngularJS applications using JavaScript patterns such as Immediately-Invoked Function Expressions (IIFE) and revealing module pattern, using JavaScript strict mode, and using explicit dependency injection.

The lengthy first chapter (almost one-fourth of the entire book) of Learning AngularJS for .NET Developers moves onto an introduction of controllers and services in AngularJS and then moves onto more detailed description of directives that were introduced by example earlier in the chapter. In particular, this section covers specific built-in AngularJS directives ngRepeat and ngInclude before looking at creation of custom AngularJS directives. The chapter concludes with a discussion of AngularJS filters.

Chapter 2: Creating an AngularJS Client-side Application in Visual Studio

The initial chapter of Learning AngularJS for .NET Developers is completely focused on AngularJS and is useful to anyone using AngularJS regardless of whether they are using .NET or not. Chapter 2 is the first chapter of Learning AngularJS for .NET Developers that includes .NET-specific details. The author states that this chapter "assumes that you already know the fundamentals of .NET web development using Visual Studio."

The second chapter of Learning AngularJS for .NET Developers introduces using VisualStudio with an empty web project that doesn't require specification of any particular web framework. The chapter then explains and demonstrates use of NuGet to download packages. Several NuGet commands run in VisualStudio are demonstrated and a quick reference is made to the NuGet command line tool. The chapter briefly discusses Visual Studio extensions in general before specifically focusing on the Web Essentials 2013 and SideWafflet extensions which the author maintains turn Visual Studio into "a powerful AngularJS IDE."

Chapter 2 builds a client-side example based on AngularJS and Bootstrap. This example explanation begins by discussing "the organization of AngularJS code" as exemplified in the AngularJS starter project angular-seed. It provides a brief overview of other approaches for organizing an AngularJS application.

Learning AngularJS for .NET Developers's second chapter looks at integrating AngularJS with JavaScript with a section on integration with native JavaScript and a section on integration with third-party JavaScript frameworks. The section of Chapter 2 on routing describes how AngularJS supports two types of routing to allow a single page application to appear to update "seamlessly" in the web browser even for different URLs. The chapter concludes with a demonstration of building a client-side application with a bicycle rental management example.

Chapter 3: Creating .NET Web Services for AngularJS

Chapter 3 of Learning AngularJS for .NET Developers begins with a brief introduction to .NET's historical support for SOAP-based web services with ASP.NET Web Services and Windows Communication Foundation (WCF). Discussion then moves into a brief overview of REST and support for REST in AngularJS. This part of the chapter introduces Hypermedia as the Engine of Application State (HATEOAS), but then states that HATEOAS will not be used in the book's examples.

A section in Chapter 3 looks at different .NET-oriented RESTful web services frameworks that can be used with AngularJS (including ASP.NET Web API) before focusing on ServiceStack. The chapter lists advantages of ServiceStack, provides a brief overview of ServiceStack, and presents a small ServiceStack example application that demonstrates several key features of ServiceStack.

After introducing the use of ServiceStack to implement web services, the third chapter of Learning AngularJS for .NET Developers looks at invoking RESTful web services from AngularJS using the ngResource module. This section includes coverage of AngularJS's Promise API.

Chapter 4: Creating an AngularJS, ASP.NET MVC, ServiceStack Application

Chapter 4 of Learning AngularJS for .NET Developers begins with discussion of advantages of ASP.NET MVC and some primary features provided by ASP.NET MVC. The chapter demonstrates how to integrate ASP.NET MVC into the "Rent that Bike!" sample application started earlier in the book and with ServiceStack. The chapter also discusses the additional complexity associated with "changing an AngularJS application to use the HTML5 History API instead of hashbang URLs."

The fourth chapter of Learning AngularJS for .NET Developers examines "ASP.NET bundling bundling and minification features for AngularJS files." The chapter also briefly describes multiple approaches for securing AngularJS applications. ServiceStack.Mvc is introduced as a means for "deeper integration" of ServiceStack and ASP.NET MVC.

The focus of Chapter 4 switches from security to approaches to "ensure that AngularJS works well with the backend." Specific approaches include alerting users to existence of long-running operations and handling exceptions with $http interceptor and the $q promise.

There is a section in Chapter 4 on database persistence. The author mentions several .NET-oriented ORM and micro-ORM frameworks, but focuses on ServiceStack.OrmLite and introduces ServiceStack.OrmLite.Sqlite32 for use with SQLLite. I also liked the author's referencing of Firefox add-on SQLite Manager.

Chapter 5: Testing and Debugging AngularJS Applications

The fifth chapter of Learning AngularJS for .NET Developers reintroduces Node.js and also mentions Node.js Tools for Visual Studio as foundational for testing AngularJS applications. The chapter demonstrates coverage of installing Node.js, installing and configuring Karma, an overview of using Jasmine and injecting mocking with $httpBackend service.

Chapter 5 introduces Protractor, which it describes as "an AngularJS-friendly wrapper around the Selenium WebDriver browser automation framework." There is a section that discusses how to install Protractor, including installing the JDK for Selenium to use. The next section describes configuration of Protractor before discussing writing Protractor tests.

Learning AngularJS for .NET Developers's fifth chapter covers several more testing-related subjects. These include testing web service endpoints, using for behavior-driven development (BDD) tests,, the moq4 framework, debugging AngularJS applications with AngularJS Batarang, and using JavaScript frameworks to deal with HTML5 validation and older web browsers.

Chapter 6: Advanced AngularJS Topics

The final chapter of Learning AngularJS for .NET Developers covers four "advanced AngularJS topics": internationalization and localization (ngLocale and angular-dynamic-locale), AngularJS animations (ngAnimate), remote web services (JSON with padding [JSONP] and Cross-origin Resource Sharing [CORS]), and template caching ($templateCache).

General Observations
  • Learning AngularJS for .NET Developers includes several code listings. These are black font on white background (no color syntax) without line numbers. However, the code can also be viewed in Visual Studio or even via Plunker (which provides color coded syntax and line numbers) using URLs provided in the book's text. The book's code listings include bold highlighting of portions of the code that are the specific focus of the associated text.
  • Learning AngularJS for .NET Developers includes useful diagrams that help to understand AngularJS's architecture and lifecycle. A couple of these are black-only on white background even in the electronic (PDF) version I reviewed. Some descriptions differentiate portions of the graphic by referring to "darker" but this can be difficult to distinguish.
  • The PDF version of Learning AngularJS for .NET Developers includes color screen snapshots (such as of using Visual Studio); I assume this is true for other electronic formats.
  • The title of Learning AngularJS for .NET Developers advertises this as a book about using AngularJS with .NET. The author frequently mentions in the book that it is assumed that the reader knows certain background technologies and concepts when reading that chapter. Even though the title and the author's many statements make this very clear, I cannot overemphasize this point: Learning AngularJS for .NET Developers is best suited for .NET developers with basic web skills who want to learn and apply AngularJS. Developers wanting to learn to use AngularHS with Java EE or some other back-end technology should look elsewhere. That stated, the single chapter that focuses exclusively on AngularJS is a nice introduction to and high-level coverage of AngularJS.
  • By assuming readers' .NET experience, Learning AngularJS for .NET Developers is able to focus primarily on AngularJS and developing applications with AngularJS and integrating AngularJS with .NET.
  • Learning AngularJS for .NET Developers is generally well-written and the text is fairly easy to follow and understand.
  • As one would expect from a book on using AngularJS with .NET, Learning AngularJS for .NET Developers provides significant coverage of applying Visual Studio and integrating AngularJS with .NET. However, it also contains quite a bit of coverage on open source and third-party products that are commonly used in applications built with AngularJS and .NET.

Learning AngularJS for .NET Developers delivers on what its title advertises. Readers of Learning AngularJS for .NET Developers should expect to learn the basics of AngularJS and how to apply AngularJS to front-ends for their .NET applications. The book does assume some .NET knowledge and experience and does devote considerable attention to using .NET frameworks and Visual Studio. I also like that the book mentions several open source projects and demonstrates integrating those with the applications built with AngularJS and .NET.