October 2009

Volume 24 Number 10

Toolbox - User Interfaces, Podcasts, Object-Relational Mappings and More

By Scott Mitchell | October 2009

Quickly Create Common User Interface Groupings

I recently started work on an order-management application for the printing operations of a large university. Each day, hundreds of professors and administrators submit production orders ranging from 100 copies of an upcoming exam to 50,000 copies of next semester's course catalog. Like most line-of-business applications, this one requires a variety of data-entry screens, each one containing dozens of user-input elements. Many of these screens share common user interface groupings. For example, the order placement screen contains a series of drop-down lists from which the user can select the paper type, the binding, and other options. This same grouping of drop-down lists is repeated in the order management screen. Many screens also share common button groupings, such as Save Progress, Submit, and Cancel.

Implementing such user interfaces, one button and one drop-down list at a time, is a tedious and time-consuming endeavor—but it doesn't have to be that way. nukeationMachine, by Nukeation Studios, can greatly reduce the time it takes to build user interfaces for Windows Presentation Foundation (WPF), WinForms, and ASP.NET applications. nukeationMachine is a Visual Studio add-in that ships with over 1,600 UI Bits—common groupings of user interface elements that can be added to the design surface in Visual Studio with a single click of the mouse. For instance, there is a UI Bit named IgnoreRetryCancel that defines a grouping of three buttons laid out horizontally and titled Ignore, Retry and Cancel. To add this grouping to your application, simply locate the UI Bit in the nukeationMachine window and click it, and those three buttons are instantly added to the design surface. To better appreciate the time savings, check out the screenshot, which shows a user interface I designed with nukeationMachine in under 30 seconds.

You can think of nukeationMachine's UI Bits as macros that define the elements to add to the design surface; selecting the UI Bit from the nukeationMachine window simply executes the macro, adding those elements to the design surface. Consequently, using nukeationMachine to implement your user interface does not add any code to your project or any dependency to nukeationMachine. It's just a lightning-fast way to add common UI groupings. What's more, if you have a UI grouping that's not already included in the 1,600 UI Bits that ship with nukeationMachine, you can package your custom grouping into a UI Bit with just a few mouse clicks.

You can buy a Single Technology Edition of nukeationMachine, which supports UI Bits for only one technology—WPF, WinForms, or ASP.NET—for $140. The Complete Edition includes support for all three and costs $280.

Price: $140 for a Single Technology Edition; $280 for the Complete Edition

.NET Podcasts

Podcasts are audio or video productions that are available for download over the Internet and are typically played on portable MP3 players. They are ideal listening material for your daily commute, for airplane flights, or for other downtimes. The podcast format allows for interactive discussions among multiple participants as well as the opportunity to explore a specific topic in more depth and in a more conversational way than is possible in a blog entry or magazine article.

There are an increasing number of high-quality, developer-focused podcasts, such as Scott Hanselman's Hanselminutes podcast, which was reviewed in the July 2009 issue (msdn.microsoft.com/magazine/dd943051.aspx). Another excellent podcast is .NET Rocks, a weekly talk show hosted by Carl Franklin and Richard Campbell. Each episode is about an hour long and focuses on a particular technology, product, or person of interest. For instance, in show #370 the duo interviewed Microsoft Senior Vice President S. Somasegar. Phil Haack discussed the ASP.NET MVC Framework in show #433. And author Julia Lerman shared her insights on the Entity Framework in show #319.

.NET Rocks Podcasts Web Site

Franklin and Campbell are both natural interviewers and do a great job picking the brains of their guests while maintaining a smooth and natural flow to the discussion. Listening to a .NET Rocks podcast is a lot like overhearing a conversation among experienced developers at a user group meeting or conference. You're bound to learn something new, hear an interesting anecdote or two, and discover how other knowledgeable developers are using .NET and related technologies in their daily jobs.

The .NET Rocks show was originally started by Franklin in 2002, and there are now more than 460 episodes. From the show's Web site you can download previous shows (as well as each week's new episode), view complete transcripts, and send in your questions or comments.

Price: Free

Configure NHibernate Using C#

NHibernate is a popular object-relational mapper (ORM) for .NET applications. Like other ORM tools, NHibernate provides a framework for persisting and retrieving data between an object-oriented domain model and a relational database, freeing developers from having to write tedious data-access code. (NHibernate was reviewed in the October 2006 issue, available at msdn.microsoft.com/magazine/cc163540.aspx.) For NHibernate to work, a mapping between the domain model and database must be defined. Such mappings have traditionally been defined through XML files, but these mappings have some drawbacks. For instance, there are no compile-time checks to ensure that the XML mapping and the properties in the domain model line up; if there is a mismatch, it is not caught until runtime. And for many developers, XML's syntax and verbosity can seem excessive and less readable than clean, terse source code.

Fluent NHibernate is an interesting open-source project that makes it possible to move the NHibernate mappings out of XML and into source code. Each entity is mapped by creating a class and defining the mapping rules in its constructor. Figures 1 and 2 show Fluent NHibernate in action. Figure 1 contains the class definitions for two objects in the domain model, Category and Product. Figure 2 shows the CategoryMap class, which defines the mapping rules between the Category object and the underlying Categories database table. Be sure to note the syntax in Figure 2. It is an example of a fluent interface, an API design style that aims at maximizing readability through the use of descriptive names and method chaining. With the NHibernate mapping rules in code, any misalignments between the mapping rules and the domain model are caught at compile time. For example, altering the Category class by renaming its CategoryId property to Id would result in a compile-time error in the CategoryMap class.

Figure 1 Category and Product Class Definitions

public class Category
public int CategoryId { get; private set; }
public string CategoryName { get; set; }
public string Description { get; set; }
public IList<Product>
Products { get; private set; }
public class Product { ... }

Figure 2 CategoryMap Class

public class CategoryMap : ClassMap<Category>
public CategoryMap()
Id(x => x.CategoryId);
Map(x => x.CategoryName)
Map(x => x.Description);
HasMany(x => x.Products)

If the structure of your object and relational models follows a set of conventions defined by Fluent NHibernate, you can use its auto-mapping feature, which removes the need to explicitly spell out the mapping rules in code. Instead, Fluent NHibernate automatically determines the mappings on your behalf. What's more, Fluent NHibernate includes capabilities to move database configuration information out of NHibernate's XML files and into source code using the same fluent interface style.

Price: Free

The Bookshelf

Working as a consultant can be an exciting, fast-paced career choice. Unlike full-time staff, consultants are usually brought on board to solve a particular problem or implement a specific technology. When that's done, you're off to a new client and a new job, and, perhaps, new technologies. Of course, consulting has its drawbacks, the main one being job security—consultants are easier to let go than full-time employees.

If you currently work for a technology consulting company, or are weighing the pros and cons of doing so, then Aaron Erickson's book "The Nomadic Developer" (Addison-Wesley, 2009) is for you. This book is divided in two: the first half gives prospective consultants an insider's look at the consulting business; the second is geared toward those already employed by a consulting firm and explores various career paths and offers advice on how to best thrive as a consultant.

"The Nomadic Developer" should be required reading for anyone currently seeking a job at a consulting company, especially those who have not previously worked as consultants. The book's second chapter, "The Seven Deadly Firms," describes seven dysfunctional traits that, if present, will negatively impact your time at the company. For each dysfunction, Erickson supplies a detailed description, explains what life is like at a consulting firm when that trait is present, and provides tips for spotting the dysfunction during a job interview. There are also chapters on the top 10 traits a technology consulting firm is looking for in applicants, and another chapter that suggests questions applicants should ask during the interview process.

In addition to Erickson's own viewpoints, "The Nomadic Developer" includes insights and anecdotes from other experienced consultants in the form of annotations and in a chapter of essays. These annotations and essays, along with Erickson's conversational writing style, make "The Nomadic Developer" an enjoyable and educational read.

Price: $39.99

**Scott Mitchell,**author of numerous books and founder of 4GuysFromRolla.com, is an MVP who has been working with Microsoft Web technologies since 1998. Mitchell is an independent consultant, trainer and writer. Reach him at Mitchell@4guysfromrolla.com or via his blog at ScottOnWriting.net.