Foreword

Like many great advances in our industry, the explicit concept of aspect-oriented programming (AOP) was developed at what is now known as PARC, a Xerox Company. Soon after, in 2001, the AspectJ extensions brought AOP to Java. Aspects have enjoyed a long history in the Java community, but for many .NET developers, aspects are still considered new and exotic. Even so, many .NET developers have been using them without knowing it.

Aspects provide a means of separating cross-cutting concerns from your core implementation code into separate modules. Rather than having every method contain logging code, for example, a logging aspect can be applied to methods external to the method implementation. It’s a powerful technique to help employ the principle of separation of concerns within code.

In AOP in .NET, Matthew D. Groves deftly shines a light on the many ways developers can take advantage of aspects in .NET. He begins with an approachable introduction to AOP and builds on that with an example of an application written without aspects, which is then cleaned up with aspects. Subsequent chapters dig deeper into the various types of aspects and how to apply them using PostSharp and Castle DynamicProxy.

Each chapter builds on the previous one in a distinct, understandable style, each with sample code that clarifies the concepts covered in the chapter. Great care was obviously put into the code samples.

One example in particular shows how aspects are not limited to intermediate language (IL) rewriting and method interception. He challenges this implicit assumption by showing an aspect that wraps an HTTP request boundary in ASP.NET through a custom HttpModule implementation. It’s an example that might not, at first glance, be thought of as an aspect. But on reflection, it obviously meets the definition. Aspects are not limited to compile-time interception. This drives home the point that many developers have been using aspects of one form or another for a long time without realizing it.

One subject near and dear to me is unit testing and this book contains an entire chapter covering the implications of unit testing and how to unit test aspects. It’s clear this book is not just meant to educate the reader on a subject, but to help the reader integrate the techniques and technologies with real-world practices.

AOP in .NET is a great resource for those interested in learning how aspects can help maintain separation of concerns in a code base. I encourage you to take a look.

PHIL HAACK

DEVELOPER, GITHUB

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

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