Last Thursday our good friend Matthew Groves delivered part 1 of his 5-part live webinar series on AOP in .NET. He has a new book coming out next month called Aspect Oriented Programming in .NET from Manning Publications and the series will cover some of the practical AOP insights found in his book and a variety of real-world coding examples using PostSharp.
In part 1, Matt does an excellent job of demonstrating the basics of Aspect-Oriented Programming, including a number of live coding examples using ASP.NET and PostSharp – all in under 30 minutes.
Q&A
Q: Can you provide any hints on unit testing with aspects involved?
A: We’re going to talk about unit testing aspects – unit testing code that aspects are applied to – in part 5 of this series [May 30th]. In fact, I have dedicated an entire chapter of my book to unit testing aspects.
Q: Is PostSharp the only AOP framework covered in your book?
A: My book is focused on AOP in .NET and PostSharp is a large part of that but I cover other .NET tools like Castle DynamicProxy and the ASP.NET examples [shown in the video]. The idea is that once you learn the principles of AOP, you will be comfortable using tools other than what’s covered in the book. So anything you learn about PostSharp or Castle you can apply to other frameworks as well.
I will be adding new recordings each week but, if you want to catch them live and have the chance to ask Matt any question you may have about AOP in .NET and/or PostSharp be sure to sign-up for the series and join us every Thursday throughout the month of May.
Mark your calendar for Thursdays in May as we kickoff a new series of live webinars with our good friend, Matthew Groves.
Matt is a developer with over 10 years of professional experience in education, consulting, and product development. He concentrates on web applications, using C# with ASP.NET, JavaScript, and PHP.
His new book Aspect Oriented Programming in .NET from Manning Publications debuts in June and we’ve put together a 5-part webinar series that will give you a taste of the practical aspect-oriented programming insights found in his book and a variety of real-world coding examples as implemented by PostSharp.
Read on to learn more about the upcoming schedule and a special offer from Manning Publications.
Sign-up for the PostSharp live webinar series today >>
SCHEDULE:
1) You May Already Be Using AOP
Thursday, May 2nd at 9:00 AM PDT |12:00 PM EDT | 4:00 PM GMT
Learn the basics of Aspect-Oriented Programming and see live coding examples of AOP frameworks that come with ASP.NET. We will also look at how to write a simple PostSharp aspect using a pattern that is similar to the ASP.NET framework.
2) Call This Instead: Intercepting Methods
Thursday, May 9th at 9:00 AM PDT |12:00 PM EDT | 4:00 PM GMT
One of the most common types of aspect is the method interception aspect, which runs a piece of code instead of the intended method. In this episode, we will look at a real-world application of the method interception aspect that can help with data transactions.
3) Before and After: Boundary Aspects
Thursday, May 16th at 9:00 AM PDT| 12:00 PM EDT | 4:00 PM GMT
A PostSharp method boundary aspect can execute code at its borders (e.g. before a method, after a method, on exception). In this episode, we will look at a real-world application of a method boundary aspect to help with caching.
4) Under the Hood of a Post-Compiler
Thursday, May 23rd at 9:00 AM PDT| 12:00 PM EDT | 4:00 PM GMT
The details of how a post-compiler like PostSharp works can be complex, but it's important to have a basic understanding of what's happening in order to make an informed decision about where and when to use it. In this episode, we will look at how to decompile a .NET assembly and view code with/without a PostSharp aspect with ILSpy.
5) Unit Testing and Thin Aspects
Thursday, May 30th at 9:00 AM PDT| 12:00 PM EDT | 4:00 PM GMT
The benefits of unit testing are numerous. When aspects are involved, keeping those aspects "thin" is a key to keeping your code easy to unit test. In the final episode we will explore some of the implications of unit testing when a post-compiler tool is involved.
SPECIAL OFFER:
Now there's even more reason to attend Matt's webinar series. The generous folks at Manning Publications are offering a big discount on AOP in .NET to all live webinar attendees. Seats are limited and this series is sure to sell out so reserve your spot today.
If you want to learn what difference AOP and PostSharp can make in your projects, and take advantage of Manning’s special discount offer, join us every Thursday throughout the month of May.
Reserve your seat for the PostSharp live webinar series now >>
Join us tomorrow, September 27th, for the next PostSharp Live Webinar when our guest will be Joe Kuemerle.
Joe is a developer and speaker in the Cleveland, OH area and specializes in .NET development, security, database and application lifecycle topics. He is currently a Lead Developer at BookingBuilder Technologies, a leading software innovator for the travel industry.
Tomorrow, Joe will show how the clutter of logging, security checks, exception handling, implementing INotifyPropertyChanged and much more can be purged from your methods with Aspect Oriented Programming (AOP) techniques.
Reserve Your Webinar Seat Now >>
During the webinar you will learn:
- Why cluttered code is a pervasive problem in software development.
- What AOP is all about, how it works and how to use it effectively.
- How AOP tools like PostSharp make applications more readable, better organized and easier to maintain.
- How to implement Logging and INotifyPropertyChanged automatically with PostSharp Toolkits.
If you've ever wondered what difference AOP and PostSharp can make in your projects, and want to gain more insight into how PostSharp Toolkits make short work of boilerplate code, be sure to attend tomorrow’s live webinar.
Space is limited
Reserve Your Webinar Seat Now >>
Last month Karol Waledzik, a software architect and team lead at Internetium, wrote a 2-part blog post about the pain WPF and Silverlight developers experience by having to manually implement change notifications.
He debuted the PostSharp Domain Toolkit and wrote about the pain it alleviates by automatically handling (nearly) all standard business cases and generating exactly the right notifications, at exactly the right time.
Last week he demoed the toolkit during a live webinar, showing how it makes short work of change notification pain for developers and sharing details on its inner-workings.
Watch the recording and learn:
- Why previous attempts to tackle INotifyPropertyChanged by other libraries fell short
- What makes the Domain Toolkit different from other libraries
- How the toolkit automates change notifications
- What other scenarios the toolkit supports automatically
- The limitations of the toolkit and available customization
The recording below includes the entire webinar plus Q&A session where Karol answered questions from the audience about the toolkit, the scenarios it currently handles and those still planned.
If you have additional questions about the Domain Toolkit, don’t hesitate to connect with our Support Desk for fast answers. If you’d like to take it out for a test drive, simply install the NuGet package.
Happy PostSharping!
-britt
Join us on Thursday, September 13th, for the next PostSharp Live Webinar when our guest will be Karol Waledzik from Internetium.
Karol is the software architect and team lead at Internetium in Warsaw, Poland, and is largely responsible for building our new line of PostSharp Toolkits.
He wrote a 2-part blog post last month about the pain most WPF developers experience by having to manually implement change notifications, and how the Domain Toolkit, the latest addition to our product family, automates this for (nearly) all standard business cases.
On Thursday’s live webinar, Karol will walk you through the PostSharp Domain Toolkit and show how it treats the implementation of INotifyPropertyChanged seriously and finally ends change notifications pain for WPF developers.
During the webinar you will learn:
- Why previous attempts to tackle INotifyPropertyChanged by other libraries fell short
- What makes the Domain Toolkit different from other libraries
- How the toolkit automates change notifications
- What other scenarios the toolkit supports automatically
- The limitations of the toolkit and available customization
If you're tired of having to manually implement INotifyPropertyChanged in WPF applications, and want to gain insight into how the PostSharp Domain Toolkit can end change notification pain in your own projects, be sure to watch Thursday's live webinar.
Space is limited.
Reserve your Webinar Seat Now >>
Last Thursday, our PostSharp MVP Yan Cui joined us for an awesome webinar about how to use AOP to get near-realtime performance information from their servers running in the Amazon Cloud, using AWS CloudWatch.
The video and slides from the live webinar are now online for your viewing pleasure:
And here are the slides:
In the second part of the webinar I give a sneak peek at the PostSharp Diagnostic Toolkit. Download and install it today via NuGet, or get the source code on Github.
Happy PostSharping!
-Igal
.jpg)
Last week we were honored to have our friends at IdeaBlade join us for a very special webinar, dealing with real world AOP usage. Ward Bell, V.P. of Technology at IdeaBlade, did an excellent job of demonstrating how Aspect-Oriented Programming and PostSharp helps creating clutter-free data access, using their flagship product, DevForce.
DevForce uses PostSharp to infuse “Code First” entity model classes - entities like Customer and Order – with rich behaviors that go way beyond property change notification. You write entities with simple getters and setters; after PostSharp, they support property validation, entity navigation, lazy loading, dirty tracking, and UI data binding.
Here is the recorded webinar and the slides for your viewing pleasure! You can download the source code for the demo application and the slides from the IdeaBlade Documentation site.
Q&A
During the webinar you have asked us great questions, and, as promised, here are the answers to all of them:
Q: Does DevForce integrate with PostSharp?
A: Yes, DevForce Code First is built with PostSharp, so you don’t need a PostSharp to use it!
Q: Does any entity with a FirstName property get that clown verifier, or just Employee?
A: Just the Employee. As you can see, the type of the entity is passed into the custom verifier:

Q: Is it possible to step through the injected behaviors?
A: Yes, if you have the requisite symbol files (pdb files) loaded. It is rare to want to step through either the PostSharp or DevForce code itself, though. You’re usually debugging your own code, such as the “NoClownsVerifier”.
Q: Can you show some of the code in IdeaBlade.Aop?
A: Here is the definition for the two aspects provided by DevForce:

As you can see, it uses PostSharp’s abilities to introduce, or inject, behaviors at compile-time to the target classes, so it implements things like INotifyPropertyChanged for you in your entities automatically!
Please note that the specific behaviors we have injected may or may not be enabled when the entity is detached. For example, entity navigation properties require the EntityManager to locate the related entities in cache or query them from the database if necessary. Validation triggered by property setting requires an attached validation engine (our VerifierEngine) which is made available to the entity instance via its attached EntityManager. Accordingly, DevForce only enables these behaviors when the entity is attached. The capability has been injected, the code has been woven into the class, but the feature is turned off for detached entities.
Q: If you add your own properties to POCO class do you need to somehow tell PostSharp not to interfere with it?
A: The [Unmapped] attribute tells DevForce (and Entity Framework) that this property is NOT mapped to a column in the database and is not persisted. DevForce won’t activate the injected behaviors for such properties either (although we are considering an attribute that would tell DevForce to enable some of the behaviors for non-persistent properties in a future release).
Q: Can you provide you own base class for navigation property collections?
A: You can take over the behavior of any property, including navigation properties, via DevForce “property interceptors”, another feature that PostSharp weaves into your entity properties. Interceptors can be specified in the entity, in the base class, or in a separate property interceptor provider that DevForce will discover (we never require a base class in Code First).
Q: How do you mark a property to not have a specific aspect apply to it?
A: If this is a PostSharp question, the answer is “it’s up to how you implement your aspects.”
The DevForce aspects are applied at the class level but you can opt out at the property level with the [Unmapped] attribute. We only have two aspects (one for entities, one for complex objects) so I think what you’re asking is about opting out of one or more of the interfaces. DevForce lets you inject your own custom behavior into our interface implementations so you can do coarse grain or fine grained alterations of our implementations.
Q: How were the Employee.cs, Customer.cs and other table classes created?
A: I could have written them entirely by hand. I found that boring so I used what we call our “Code Second” technique. I pointed the EF Designer at the database and asked it to generate code with our “Code First” T4 code generator. Then I threw away the EDMX and went to town, cleaning out anything I didn’t like in the generated entity classes. What you see is what I decided to keep.
Q: How do you convert an existing “Database First” to the code-first model?
A: You might try the Code Second technique that I described above.
Q: How is the raising change notification done on the FullName property in the Employee class?
A: I used DevForce property interception feature which is also woven into the properties via AOP. I added the following code at the bottom of the Employee class:

DevForce recognizes this as an Employee property interceptor for FirstName and LastName. The implementation raises PropertyChanged when either of those properties has finished setting its value.
We are considering the possibility of automating discovery of FullName’s dependence upon FirstName and LastName but that capability is not in this release.
Final words
We hope that you enjoyed this very special webinar! If you have any more questions about how to use PostSharp, please visit our Support Forums to have them answered. For more information about DevForce and IdeaBlade, please visit their website.
We thank Ward Bell and IdeaBlade for the wonderful presentation and the Q&A! See you all next time!
Until then,
Happy PostSharping!
-Igal
Join us on Thursday, February 23 at 9:00 AM PST | 12:00 PM EST | 5:00 PM GMT for the next PostSharp Live Webinar when our guest will be Ward Bell.
Ward is V. P. of Technology at IdeaBlade and, with over 25 years of application development experience, he champions the company's customer-focused product direction.
Due to the popular demand of last week's live webinar, we've asked Ward to join us again to show how IdeaBlade's DevForce product uses PostSharp to infuse “Code First” entity model classes - entities like Customer and Order – with rich behaviors that go way beyond property change notification.
During the webinar you will learn:
- How IdeaBlade uses PostSharp to achieve important product goals
- Which alternatives to PostSharp the company considered, and rejected
- What initially worried IdeaBlade about using AOP and PostSharp
- Where IdeaBlade is planning to go next with PostSharp
If you've ever wondered what difference AOP and PostSharp can make in real products, and want to gain insight into how it can help with your own project, be sure to watch Thursday's webinar.
Happy PostSharping!
-Britt
Wow! What a turnout for my first webinar! Thank you all for attending, I had a great time presenting it, and will continue to do more webinars in the future. The webinar was recorded, and the video is now online for your viewing:
As promised, here are the answers to the great questions you asked, which I didn’t have the chance to answer during the live webinar. As always, you can always ask your questions on our Support Forums.
Q: Any reason the [aspect] class must be Serializable?
A: At (post) compilation, the aspect is serialized using binary serialization, and added as a resource to the target process. Then at runtime, the aspect is deserialized. PostSharp will emit a compilation error if you forget to mark your aspect as Serializable.
Q: What is the typical use case for creating interfaces using PostSharp?
A: One typical scenario for implementing interfaces with PostSharp is implementing INotifyPropertyChanged in WPF to support Data Binding.
Q: Are the OnExit and OnEnter aspects thread safe? How would one make it thread safe if it is not?
A: While the aspects themselves are thread-safe, shared state (i.e. custom fields) within the aspects is not. To safely pass data around between OnEnter and OnExit events, you can use the MethodExecutionArgs.MethodExecutionTag property.
Q: What about signed DLLs and PostSharp?
A: PostSharp has no problems with signed DLLs – they will be re-signed after the post-compilation process.
Q: What about Silverlight DLL's, is it also available?
A: Of course, PostSharp comes with the Silverlight assemblies included, you need to add a reference to the PostSharp.SL.dll instead of PostSharp.dll. For more information, please refer to the online documentation.
Q: Can you provide a good definition of aspect oriented programming?
A: Aspect Oriented Programming complements traditional OOP by allowing us to encapsulate infrastructure code (such as logging, security, validation, etc.) into small modules called aspects, and then apply those aspects throughout the entire system in such way that the business logic is completely separated from those concerns.
So go ahead, download the free starter edition now!
Happy PostSharping!
-Igal
Boilerplate code. It’s all around us, polluting our business logic, and forcing us to write the same code over and over again. Join us on Thursday, January 26th, as our very own Igal Tabachnik shows you how to stay DRY (Don’t-Repeat-Yourself) by using aspect-oriented programming (AOP) and PostSharp to remove boilerplate code that’s duplicated in and across systems.
Attendees will learn:
- Why the DRY principle matters
- How AOP helps to remove boilerplate code
- How to use PostSharp to produce cleaner code
- Real-world AOP usage examples
Oh, and that’s not all – we’re giving away two PostSharp licenses to two lucky attendees!
So hurry up, sign up here: https://www3.gotomeeting.com/register/724468246