Book Review: Expert C# Business Objects

A few weeks back, I was talking to a fellow member of the West Michigan .NET User Group board, and we were discussing the architectural model behind the business objects that we used on the NxOpinion project. The more we talked, the more he said that our approach sounded similar to a framework called CSLA that he was reading about in Rocky Lhotka’s book, Expert C# Business Objects . He showed me an application that he was building using the CSLA framework, and I was intrigued.

I’m familiar with Rocky’s name, and I’ve run across his books for years, but I had never actually picked one up and thumbed through it. Even a quick glance through his latest book interested me enough to purchase a copy. It sounded so much like the approach we had taken that I had to read someone else’s perspective. Along the way, I hoped to pick up some tips about areas that we haven’t had the time to expand upon.

First, let me say that the publisher, Apress, lists a user level of “advanced” on the back cover of the book. Although I mostly agree with that assessment, I also think that with enough dedication, this is a book that can be understood by an intermediate developer. And I think that most of the intermediate developers that I know who write business applications using .NET should read it.

Rocky’s book covers so much good material in its 791 pages, that it would be tough to summarize it in a short review. If you follow him through the whole book, by the end, you’ll have a reusable framework for creating “undoable”, bindable business objects that know how to validate and persist themselves either on the local machine or across a network. Although you could cut-to-the-chase and simply download CSLA from his web site, the power of this book is in following his thought process through the planning, design, and implementation of the entire framework.

I really like the way Rocky explains why object-orientation is so important to building good business objects. By creating objects that know how to defend themselves from bad data, persist themselves to a database or other storage system, track multiple versions for undo support, and make themselves easily remotable, he shows the reader the importance of encapsulation and its effect on the maintenance and extensibility of the entire system. In my time, I’ve seen way too many architectures that depend on strongly-typed datasets for their “business objects” with poorly factored business rules scattered throughout every application layer.

If you’ve ever wondered about serialization, remoting, custom attributes, security, or reflection, Rocky does an excellent job putting these technologies in perspective and provides the reader with appropriate prescriptive guidance about how and when to use all of them. Of course, you could read entire books about each of these technologies, but the point is that Expert C# Business Objects relates all of this to a practical and useful framework that almost anyone can understand.

Although .NET Remoting is currently a controversial subject when it comes to Microsoft technologies, the principals and considerations that Rocky discusses are still germane. Keep in mind that with all of the noise surrounding Service Oriented Architectures (SOA) and web services, at the end of the day, functionality that meets business objectives and provides customer value is all that matters. Fortunately for CSLA, remoting technology is still supported in Indigo. However, prepare yourself for a little controversy if you get into a technical discussion about remoting versus web services and this framework.

The writing in Business Objects is very good, and Rocky takes his time to carefully explain all of the concepts. Years ago, I had a side job doing technical editing for upcoming books, and I often wrote little comments about related tidbits of information that would help complete a thought or section. While reading this book, It surprised me how frequently I thought about something that would be useful, only to find Rocky mentioning it in the next sentence.

After building the CSLA framework in the first half of the book, the second half of the book goes on to show how to use the framework in sample Windows Forms and Web Forms (ASP.NET) applications, as well as exposing functionality through a web services interface. He closes out the book with a chapter on reporting and batch processing, two areas where object-oriented architectures have commonly had performance issues. Overall, the samples are very practical. It’s easy to see how they align with “real-world” applications.

If you find yourself struggling with application layering, or if you’ve always wondered how to implement undo functionality in a deeply nested object graph, this book will provide a perspective on at least one approach that has been adapted to take advantage of .NET. It’s apparent that Rocky has been refining his framework over many years, and even a casual search of the internet will turn up a number of articles related to CSLA.

As I mentioned earlier, I think that an intermediate developer can benefit greatly from this material. Even if you don’t end up using his framework, this is an excellent book with a lot of very good instruction on design decisions and related technologies. You may struggle through some of the more technical sections, but even if you only pick up 50% of the material, it is a worthwhile read. I highly recommend this book for anyone developing business applications in .NET…and that’s probably just about anyone reading this review. Thanks to Ray for pointing this out to me.

For related material, check out Rocky’s most recent .NET Rocks! appearance where he discusses the content in this book. Or, read through David Hayden’s chapter-by-chapter review.