Cover image for AOP in .NET : practical aspect-oriented programming
Title:
AOP in .NET : practical aspect-oriented programming
Personal Author:
Publication Information:
Shelter Island, NY : Manning Publications Co., c2013.
Physical Description:
xxii, 274 p. : ill. ; 24 cm.
ISBN:
9781617291142
General Note:
Includes index.

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010319104 QA76.64 G845 2013 Open Access Book Book
Searching...

On Order

Summary

Summary

Summary

AOP in .NET introduces aspect-oriented programming to .NET developers and provides practical guidance on how to get the most benefit from this technique in your everyday coding. The book's many examples concentrate on modularizing non-functional requirements that often sprawl throughout object-oriented projects. Even if you've never tried AOP before, you'll appreciate the straightforward introduction using familiar C#-based examples. AOP tools for .NET have now reached the level of practical maturity Java developers have relied on for many years, and you'll explore the leading options, PostSharp, and Castle DynamicProxy.

About the Technology

Core concerns that cut across all parts of your application, such as logging or authorization, are difficult to maintain independently. In aspect-oriented programming (AOP) you isolate these cross-cutting concerns into their own classes, disentangling them from business logic. Mature AOP tools like PostSharp and Castle DynamicProxy now offer .NET developers the level of support Java coders have relied on for years.

About this Book

AOP in .NET introduces aspect-oriented programming and provides guidance on how to get the most practical benefit from this technique. The book's many examples concentrate on modularizing non-functional requirements that often sprawl throughout object-oriented projects. You'll appreciate its straightforward introduction using familiar C#-based examples.

This book requires no prior experience with AOP. Readers should know C# or another OO language.

What's Inside

Clear and simple introduction to AOP Maximum benefit with minimal theory PostSharp and Castle DynamicProxy

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Author

Matthew D. Groves is a developer with over ten years of professional experience working with C#, ASP.NET, JavaScript, and PHP.

Table of Contents

PART 1 GETTING STARTED WITH AOP Introducing AOP Acme Car Rental PART 2 THE FUNDAMENTALSOF AOP Call this instead: intercepting methods Before and after: boundary aspects Get this instead: intercepting locations Unit testing aspects PART 3 ADVANCED AOP CONCEPTS AOP implementation types Using AOP as an architectural tool Aspect composition: example and execution


Author Notes

Matthew D. Groves is a developer with over ten years of professional experience working with C#, ASP.NET, JavaScript, and PHP.


Table of Contents

Forewordp. xiii
Prefacep. xv
Acknowledgmentsp. xvii
About this bookp. xix
Part 1 Getting Started With AOPp. 1
1 Introducing AOPp. 3
1.1 What is AOP?p. 4
Featuresp. 4
Benefitsp. 8
AOP in your daily lifep. 13
1.2 Hello, Worldp. 14
1.3 Summaryp. 19
2 Acme Car Rentalp. 21
2.1 Start a new projectp. 22
Business requirementsp. 23
Necessary nonfunctional requirementsp. 24
2.2 Life without AOPp. 24
Write the business logicp. 25
Testing the business logicp. 28
Add loggingp. 29
Introducing defensive programmingp. 31
Working with transactions and retriesp. 32
Handling exceptionsp. 35
Refactor without AOPp. 38
2.3 The cost of changep. 43
Requirements will changep. 43
Small versus large projectsp. 43
Signature changesp. 44
Working on a learnp. 45
2.4 Refactor with AOPp. 45
Start simple and isolate the loggingp. 45
Refactor defensive programmingp. 47
Creating an aspect for transactions and retriesp. 49
Put exception handling into its own classp. 50
2.5 Summaryp. 52
Part 2 The Fundamentals of AOPp. 53
3 Call this instead: intercepting methodsp. 55
3.1 Method interceptionp. 56
PostSharp method interceptionp. 57
Castle DynamicProxy method interceptionp. 60
3.2 Real-world example: data transactionsp. 63
Ensuring data integrity with begin and commitp. 63
When transactions go bad: rollbackp. 67
When all else fails, retryp. 67
3.3 Real-world example: threadingp. 70
The basics of.NET threadingp. 70
UI threads and worker threadsp. 71
Declarative threading with AOPp. 74
3.4 Summaryp. 77
4 A Before and after: boundary aspectsp. 79
4.1 Boundary aspectsp. 80
PostSharp method boundingp. 80
Method boundaries versus method interceptionp. 83
ASP.NET HttpModule boundingp. 88
4.2 Real-world example: detecting mobile usersp. 92
Offer a link to an applicationp. 93
Don't be a pestp. 99
4.3 Real-world example: cachingp. 100
ASP.NET Cachep. 102
An application that could benefit from cachingp. 103
Caching a resultp. 108
Retrieving from the cachep. 110
A more robust cache keyp. 113
4.4 Summaryp. 114
5 Get this instead: intercepting locationsp. 115
5.1 Location interceptionp. 116
Fields and properties in .NETp. 116
PostSharp location interceptionp. 118
5.2 Real-world example: lazy loadingp. 119
Lazy loading approaches in .NETp. 120
Implementing lazy loading with AOPp. 121
What about lazy-loading fields?p. 124
5.3 Real-world example: INotifyPropertyChangedp. 128
Using INotifyPropertyChanged in a desktop applicationp. 128
Problems and constraints with INotifyPiopertyChangedp. 132
Reducing boilerplate with AOPp. 134
5.4 Summaryp. 138
6 Unit testing aspectsp. 141
6.1 Writing tests with NUnitp. 142
Writing and running NUnit testsp. 142
Testing strategies for aspectsp. 145
6.2 Castle DynamicProxy testingp. 147
Testing an interceptorp. 147
Injecting dependenciesp. 149
6.3 PostSharp testingp. 156
Unit testing a PostSharp aspectp. 157
Injecting dependenciesp. 158
Problems with PostSharp and testingp. 162
6.4 Summaryp. 168
Part 3 Advanced AOP Conceptsp. 169
7 AOP implementation typesp. 171
7.1 How does AOP work?p. 172
7.2 Runtime weavingp. 172
Proxy pattern revisitedp. 173
Dynamic proxiesp. 176
7.3 Compile-time weavingp. 183
Postcompilingp. 184
Before and afterp. 184
7.4 Runtime versus compile-time weavingp. 188
Pros of runtime weavingp. 189
Pros of compile-time weavingp. 189
7.5 Summaryp. 190
8 Using AOP as an architectural toolp. 191
8.1 Compile-time initialization and validationp. 192
Initializing at compile limep. 193
Validating the correct use of an aspectp. 195
Real-world example: Threading revisitedp. 197
8.2 Architectural constraintsp. 199
Enforcing architecturep. 200
Real-world example: NHibernate and virtualp. 203
8.3 Multicastingp. 205
At the class levelp. 206
At the assembly levelp. 210
8.4 Summaryp. 211
9 Aspect composition: example and executionp. 213
9.1 Using multiple aspectsp. 214
9.2 Aspect roles with PostSharpp. 215
PostSharp aspect rolesp. 217
Role dependenciesp. 217
9.3 Composing aspects with DynamicProxyp. 219
Ordering aspectsp. 219
Reducing repetition with custom conventionsp. 222
9.4 Real-world example: caching and authorizationp. 224
Application architecturep. 225
PostSharpp. 232
Castle DynamicProxyp. 236
9.5 Summaryp. 241
Appendix A Ecosystem of .NETAOP toolsp. 243
Appendix B NuGet basicsp. 257
Indexp. 265