About this Book

Aspect-oriented programming (AOP) is a concept that is too often surrounded by dense language and academic terminology, which can make it difficult for a working developer—who is already short on time and struggling to meet deadlines—to understand, apply, and get value from AOP quickly. It’s unfortunate, because at its core, AOP is much less difficult than it sounds and can provide immediate benefits to real-world projects.

My goal has been to write the book that I wish I had read years ago and to show that AOP is much easier done than said. To that end, this book is somewhat informal in tone and short on theory, and it contains lots of code samples, with which I hope you follow along.

As much as I want this book to take a generalized approach to AOP, in order to show you real aspects I have to use real tools. I have chosen PostSharp (specifically, the free version, PostSharp Express edition) as the primary framework that I will be using most often. Castle DynamicProxy examples are also used frequently. I also discuss some of the advanced features of the paid version of PostSharp, and other tools and frameworks will be used and discussed in the course of the book, as well as in appendix A.

Roadmap

Chapter 1 introduces AOP. It covers some of the features and terms that are used in AOP. You will also write a “Hello, World” aspect.

Chapter 2 is a complete project tutorial. You will start a new project, implement features, add cross-cutting concerns, and then refactor it using AOP.

Chapters 3, 4, and 5 cover different types of aspects in more detail, with real-world examples for each.

Chapter 6 discusses the impact that AOP has on unit testing. You’ll learn how to write unit tests for aspects and write unit tests for code on which aspects are used.

Chapter 7 discusses the implementation details of how AOP tools work. You have a choice of weaving style that will dictate both the capabilities and the trade-offs involved in the two major categories of AOP tools.

Chapter 8 covers some of the architectural concerns involved in using AOP, as well as the architectural abilties that it can give you.

Chapter 9 explores what happens when you need to use multiple aspects on the same piece of code. This chapter’s real-world example also provides a capstone example that shows many of the concepts from chapters 1 through 8 working in concert.

Appendix A describes the ecosystem of .NET AOP tools, including both compile-time and runtime tools. Appendix B covers NuGet basics.

Who should read this book?

This book is primarily for developers and architects looking to reduce repetition and boilerplate in their projects. Generally speaking, the type of developer who will get the most out of this book is a developer faced with large projects that can have a lot of repetition and boilerplate. Small or tiny projects can still benefit from AOP—just not as much.

This book assumes that you have a working knowledge of C# and .NET. I also assume some familiarity with design patterns, architecture, and inversion of control. The nature of cross-cutting concerns means that AOP is involved with multiple areas of focus, including UI, databases, caching tools, threading frameworks, and so on. When possible, I try to give as much context as I reasonably can without going too far into a rabbit-hole of subject matter that has been covered more completely by other books.

Code conventions and downloads

This book includes many examples involving AOP. Most often, these examples are in C#, but sometimes they use other languages such as HTML, XAML, or plain XML. Source code in listings, or in text, is in a fixed-width font like this to separate it from ordinary text. Whenever C# class names, method names, variables, and other elements are mentioned in text, they will also be displayed in a fixed-width font. Code annotations accompany many of the code listings, highlighting important concepts.

Some of the examples are long. Often they have been reformatted with indentation and line breaks to fit in the space allotted in this book. The full source code is available for you on GitHub (https://github.com/mgroves/AOPinNET) and from the publisher’s website at www.manning.com/AOPin.NET. The instructions to use the samples in this book are mentioned briefly in the chapters, and more details about NuGet are available in appendix B.

Author Online

The purchase of AOP in .NET includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and other users. To access the forum and subscribe to it, visit http://manning.com/AOPin.NET. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). Let your voice be heard, and keep the author on his toes!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the author

MATTHEW D. GROVES is a guy who loves to code. It doesn’t matter if it’s “enterprisey” C# apps, cool jQuery stuff, contributing to OSS, or rolling up his sleeves to dig into some PHP. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parents’ pizza shop back in the 1990s. He currently works from home in Columbus, Ohio, on the Telligent product team. He loves spending time with his wife and two children, watching the Cincinnati Reds, and getting involved in the developer community. He also teaches at Capital University in Columbus, Ohio.

You can find Matthew’s blog at http://crosscuttingconcerns.com. Trade insults, horse jokes, and funny cat pictures with him on Twitter at http://twitter.com/mgroves.

About the cover illustration

The figure on the cover of AOP in .NET is captioned a “Farmer from Kastela, Dalmatia, Croatia.” The illustration is taken from the reproduction published in 2006 of a 19th-century collection of costumes and ethnographic descriptions entitled Dalmatia by Professor Frane Carrara (1812-1854), an archaeologist and historian, and the first director of the Museum of Antiquity in Split, Croatia. The illustrations were obtained from a helpful librarian at the Ethnographic Museum (formerly the Museum of Antiquity), itself situated in the Roman core of the medieval center of Split: the ruins of Emperor Diocletian’s retirement palace from around AD 304. The book includes finely colored illustrations of figures from different regions of Croatia, accompanied by descriptions of the costumes and of everyday life.

Once an ancient Greek port, a stopover point for Roman soldiers and a summer place for Croatian kings, Kastela is today a popular tourist resort on the Adriatic coast. Along its long sandy beaches there are terraces and lookouts, tennis courts and other sports grounds, and hotels and villas, surrounded by the lush greenery of pine and tamaris trees. The man on the cover, clearly a prosperous farmer from the region, is wearing black woolen trousers and a red vest over a white linen shirt. On his shoulders is a fur cape, and a red belt, red cap, and red socks complete the outfit; in his hand he holds a satchel. The rich and colorful embroidery on his costume is typical for this region of Croatia.

Dress codes have changed since the 19th century and the diversity by region, so rich at the time, has faded away. It is now hard to tell apart the inhabitants of different continents, let alone different towns or regions. Perhaps we have traded cultural diversity for a more varied personal life—certainly for a more varied and fast-paced technological life.

At a time when it is hard to tell one computer book from another, Manning celebrates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by illustrations from collections such as this one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset